/*
https://vijos.org/p/1028
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#define rep(i,x,y) if ((x)<=(y)) for (register int i=(x);i<=(y);i++)
using namespace std;
bool pd(string s1,string s2)
{
rep(i,0,s1.length()-1)
if (s1[i]!=s2[i])
return false;
return true;
}
int main()
{
int n,f[10000],ans=0;
string s[10000];
cin>>n;
rep(i,1,n)
f[i]=1;
rep(i,1,n)
cin>>s[i];
rep(i,1,n)
rep(j,1,i-1)
{
if (s[j].length()>s[i].length())
continue;
if (pd(s[j],s[i]) and f[j]>f[i]-1)
f[i]=f[j]+1;
}
rep(i,1,n)
ans=max(ans,f[i]);
cout<<ans;
return 0;
}
LIS