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(100005);
int n, ans, mx, len[maxn];
string s[maxn];
int main() {
  int i, j, c, cnt, lmx, rmx, nmx;
  ios ::sync_with_stdio(false);
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> s[i], len[i] = s[i].size();
  for (c = 0; c < 26; ++c) {
    mx = cnt = 0;
    for (i = 0; i < len[1]; ++i)
      if (s[1][i] - 'a' == c)
        ++cnt;
      else
        mx = max(mx, cnt), cnt = 0;
    mx = max(mx, cnt);
    for (i = 2; i <= n; ++i) {
      lmx = rmx = 0;
      for (j = 0; j < len[i]; ++j) {
        if (s[i][j] - 'a' != c) break;
        ++lmx;
      }
      for (j = len[i] - 1; ~j; --j) {
        if (s[i][j] - 'a' != c) break;
        ++rmx;
      }
      nmx = cnt = 0;
      for (j = 0; j < len[i]; ++j)
        if (s[i][j] - 'a' == c)
          ++cnt;
        else
          nmx = max(nmx, cnt), cnt = 0;
      if (lmx == len[i])
        mx = len[i] + mx * len[i] + mx;
      else
        mx = mx ? lmx + rmx + 1 : max(lmx, rmx);
      mx = max(mx, nmx);
    }
    ans = max(ans, mx);
  }
  cout << ans << endl;
  return 0;
}
