# 2946: [Poi2000]公共串 后缀自动机

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 10005
using namespace std;
char s[N];
int n,cnt,last,S;
int fa[N],ch[N][26],len[N],now[N],ans[N],q[N],cc[N];
inline void insert(int c)
{
int p=last,np=++cnt; last=np;
len[np]=len[p]+1;
while (p&&!ch[p][c]) ch[p][c]=np,p=fa[p];
if (!p) fa[np]=S;
else
{
int q=ch[p][c];
if (len[p]+1==len[q]) fa[np]=q;
else
{
int nq=++cnt; len[nq]=len[p]+1;
memcpy(ch[nq],ch[q],sizeof(ch[q]));
fa[nq]=fa[q]; fa[np]=fa[q]=nq;
while (ch[p][c]==q) ch[p][c]=nq,p=fa[p];
}
}
}
inline void solve()
{
scanf("%s",s+1);
int l=strlen(s+1);
int p=1,tmp=0;
memset(now,0,sizeof(now));
for (int i=1;i<=l;i++)
{
int c=s[i]-'a';
while (p&&!ch[p][c]) p=fa[p];
if (!p) p=1,tmp=0;
else tmp=min(tmp,len[p])+1,p=ch[p][c];
now[p]=max(now[p],tmp);
}
for (int i=cnt;i;i--) now[fa[q[i]]]=max(now[fa[q[i]]],now[q[i]]);
for (int i=1;i<=cnt;i++) ans[i]=min(ans[i],now[i]);
}
int main()
{
scanf("%d",&n);
scanf("%s",s+1);
int l=strlen(s+1);
S=last=++cnt;
for (int i=1;i<=l;i++)
insert(s[i]-'a');
for (int i=1;i<=cnt;i++) ans[i]=len[i];
for (int i=1;i<=cnt;i++) ++cc[len[i]];
for (int i=1;i<=cnt;i++) cc[i]+=cc[i-1];
for (int i=cnt;i;i--) q[cc[len[i]]--]=i;
for (int i=1;i<n;i++) solve();
int Ans=0;
for (int i=1;i<=cnt;i++)
Ans=max(Ans,ans[i]);
cout << Ans << endl;
}