/*
是最长子序列的变形题 直接做的话会TLE 因为有25000组数据
但是我们可以减少结点数目 通过改变当前单词 在利用二分查找 是否有这个单词 可以减少时间
*/
#include<cstdio>
#include<cstring>int d[25010];
char str[25010][20];
int add(char *t,int pos,char c)
{
char p[20];
int l = strlen(t),lp=0;
for(int i = 0; i <= l; i++)
{
if(i==pos) p[lp++] = c;
if(i < l)
p[lp++] = t[i];
}
p[lp] = '\0';
strcpy(t,p);
}
int dele(char *t,int pos)
{
int l = strlen(t);
for(int i = pos; i < l-1; i++)
t[i] = t[i+1];
t[l-1] = '\0';
}
int rechange(char *t,int pos,char c)
{
t[pos] = c;
}
int seek(int x,int y,char *t)
{
int l = x,r = y,mid;
while(l <= r)
{
mid = (l+r)/2;
int mp = strcmp(t,str[mid]);
if(mp < 0)
r = mid - 1;
else if(mp > 0)
l = mid + 1;
else return mid;
}
return -1;
}
int max(int x,int y)
{
return x>y?x:y;
}
int dp(char *t, int p)
{
int x = seek(0,p-1,t);
if(x!=-1)
d[p] = max(d[p],d[x]+1);
}
int main()
{
int n = 0,res=-1;
while(scanf("%s",str[n++])!=EOF);
memset(d,0,sizeof(d));
for(int i = 0; i < n; i++)
{
int l = strlen(str[i]);
char temp[20];
for(int j = 0; j <= l; j++)
{
strcpy(temp,str[i]);
for(char k = 'a'; k <= 'z'; k++)
{
if(j < l)
{
strcpy(temp,str[i]);
//puts(temp);
rechange(temp,j,k);
//puts(temp);
dp(temp,i);
}
strcpy(temp,str[i]);
add(temp,j,k);
dp(temp,i);
}
if(j < l)
{
strcpy(temp,str[i]);
dele(temp,j);
dp(temp,i);
}
}
res = max(res,d[i]);
}
printf("%d\n",res+1);
return 0;
}