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 = 100000;
int n, len, MAX[26], lst[maxn + 5];
char s[maxn + 5];
int main() {
  for (int i = (scanf("%d", &n), 1); i <= n; i++) {
    scanf("%s", s + 1);
    int len = strlen(s + 1), L = 1, R = 1;
    for (int i = 1; i <= len; i++)
      lst[i] = (s[i - 1] == s[i] ? lst[i - 1] + 1 : 1);
    for (int i = 2; i <= len && s[i - 1] == s[i]; i++) L++;
    for (int i = len; i >= 2 && s[i] == s[i - 1]; i--) R++;
    for (int i = 0; i < 26; i++)
      if (L != len || (s[1] - 'a') != i) MAX[i] = (MAX[i] ? 1 : 0);
    if (L == len)
      MAX[(s[1] - 'a')] = (MAX[(s[1] - 'a')] + 1) * len + MAX[(s[1] - 'a')];
    else
      MAX[(s[1] - 'a')] = MAX[(s[1] - 'a')] + L,
                  MAX[(s[len] - 'a')] = MAX[(s[len] - 'a')] + R;
    for (int i = 1; i <= len; i++)
      MAX[(s[i] - 'a')] = max(MAX[(s[i] - 'a')], lst[i]);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, MAX[i]);
  printf("%d\n", ans);
  return 0;
}
