9
lfpgbnlzyn
c
s
w
r
m
q
y
yinfblfcdhidphyfvgkxyuwomahiibbhnigdslsguhjkplibnhhrshtekwgefxeugyyyyy
 6
u
p
m
z
v
vv
 4
qe
nd
iqryhukieskfvaeettersinksrmazelxtgvartuz
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 6
nf
ysvchtjkfgsbyfzxjaykey
advqnf
wl
pi
ppppfvvmaebvhkoagppppp
 3
j
k
kkailgwqnxtdsttkkkkkkk
 4
o
yhnx
e
ennn
 10
j
dyfu
udzj
wwow
xtnw
f
c
q
o
gggg
 6
w
g
c
j
y
f
 4
r
o
w
wwwwwwwwww
 2
zxwp
ppppctfisvflhtjggg
 5
m
g
u
t
tttt
 2
n
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 3
lt
en
eeeeeeeeee
 4
vr
hp
l
llbn

7 5 541 10 10 4 4 1 21 5 9 93 21 3
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e3 + 9, maxV = 62, MOD = 998244353, AND = (1 << 20) - 1,
          lg = 21;
vector<string> arr;
int n, ans;
int entrem(const string &st, char c) {
  int bes = 0;
  for (int i = 0, j = 0; i < st.size(); i = j) {
    for (; j < st.size() && st[i] == st[j]; j++)
      ;
    if (st[i] == c) bes = max(bes, j - i);
  }
  return bes;
}
int prefi(const string &st, char c) {
  int ans = 0;
  while (st[ans] == c) ans++;
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  arr.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int u = 0; u < 26; u++) {
    int cr = 0;
    for (string st : arr) {
      if (st == string(st.size(), char('a' + u))) {
        cr = cr + (cr + 1) * st.size();
      } else if (st.find(char('a' + u)) == string::npos) {
        cr = min(cr, 1);
      } else {
        int nuevo = 0;
        nuevo = max(nuevo, entrem(st, char('a' + u)));
        if (cr > 0) {
          int uno = prefi(st, char('a' + u));
          reverse(st.begin(), st.end());
          nuevo = max(nuevo, uno + 1 + prefi(st, char('a' + u)));
        }
        cr = max(cr, nuevo);
      }
    }
    ans = max(cr, ans);
  }
  cout << ans << '\n';
}
