#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define AC "test"
#define foru(i, l, r) for (int i = (l); i <= (r); i++)
#define ford(i, l, r) for (int i = (l); i >= (r); i--)
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;
const ll inf = 1e9 + 7;
const ll linf = 1e18 + 7;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 7;
const int base = 31;
void fastIO(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
ll mul(ll a, ll b){
a%=mod;
ll res = 0;
while (b){
if (b%2) res = (res + a)%mod;
a = (a + a)%mod;
b/=2;
}
return res;
}
ll Pow(ll a, ll b){
ll ans = 1;
while (b){
if (b % 2) ans = mul(ans, a);
a = mul(a, a);
b/=2;
}
return ans;
}
ll n, cur, hashs[maxn], val, res, pow1[maxn];
int child[maxn][27], cnt[maxn];
string s;
ll gethash(int i, int j){
return (hashs[j] - mul(hashs[i-1], pow1[j-i+1]) + mod)%mod;
}
void update(string t, ll tmp){
int u = 0;
for (char c: t){
if (!child[u][c - 'A']) child[u][c - 'A'] = ++cur;
u = child[u][c - 'A'];
}
cnt[u] = tmp;
}
ll get(string t){
ll pre = 0;
ll ans = 0;
int u = 0;
foru(i, 0, t.size() - 1){
if (!child[u][t[i] - 'A']) return ans;
u = child[u][t[i] - 'A'];
pre = (pre * 31 + t[i] - 'A' + 1) % mod;
ll suf = gethash(t.size() - i, t.size());
if (pre != suf) continue;
ans = max(ans, (ll)cnt[u]);
}
return ans;
}
void solve(){
memset(cnt, 0, sizeof(cnt));
memset(child, 0, sizeof(child));
cur = 0;
pow1[0] = 1;
cin >> n;
foru(i, 1, 2000000){
pow1[i] = (pow1[i - 1] * 31) % mod;
}
res = 0;
foru(j, 1, n){
cin >> s;
hashs[0] = 0;
foru(i, 1, s.size()){
hashs[i] = (hashs[i - 1] * 31 + s[i - 1] - 'A' + 1) % mod;
}
val = get(s) + 1;
res = max(res, val);
update(s, val);
}
cout << res;
}
int main(){
fastIO();
if (fopen(AC".inp", "r")){
freopen(AC".inp", "r", stdin);
freopen(AC".out", "w", stdout);
}
solve();
}