#include<cstdio>
#include<algorithm>
#include<cstring>
//#include"debug.h"
using namespace std;
short dp[6][2010][2010],n,mi,ans,i,j,k,len[6],f[6][2010];
char s[6][2010];
int main()
{
freopen("pow.in","r",stdin);
freopen("pow.out","w",stdout);
scanf("%d",&n);
for (i=1;i<=n;i++){
scanf("%s",s[i]+1);
len[i]=strlen(s[i]+1);
}
for (i=2;i<=n;i++){
for (j=len[1];j>0;j--)
for (k=len[i];k>0;k--)
if (s[1][j]==s[i][k]) dp[i][j][k]=dp[i][j+1][k+1]+1;
for (j=1;j<=len[1];j++)
for (k=1;k<=len[i];k++)
f[i][j]=max(f[i][j],dp[i][j][k]);
}
for (i=1;i<=len[1];i++){
mi=9999;
for (j=2;j<=n;j++) mi=min(mi,f[j][i]);
ans=max(ans,mi);
}
printf("%d\n",ans);
return 0;
}