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;
int n;
long long len, mx[300], now[300], now1[300], Ans, len0, len1, ch1, ch0;
char s[200005];
int main() {
  scanf("%d", &n);
  scanf("%s", s);
  len = strlen(s);
  long long tmp = 0;
  for (int i = 0; i < len; i++) {
    if (i == 0 || s[i] != s[i - 1])
      tmp = 1;
    else
      tmp++;
    now[s[i]] = max(now[s[i]], tmp);
  }
  for (int o = 2; o <= n; o++) {
    scanf("%s", s);
    len = strlen(s);
    long long tmp = 0;
    for (int i = 'a'; i <= 'z'; i++) now1[i] = 0;
    for (int i = 0; i < len; i++) {
      if (i == 0 || s[i] != s[i - 1])
        tmp = 1;
      else
        tmp++;
      now1[s[i]] = max(now1[s[i]], tmp);
    }
    len0 = 1;
    ch0 = s[0];
    len1 = 1;
    ch1 = s[len - 1];
    for (int j = 1; j < len; j++)
      if (s[j] == s[0])
        len0++;
      else
        break;
    for (int j = len - 2; j >= 0; j--)
      if (s[j] == s[len - 1])
        len1++;
      else
        break;
    if (len0 == len) {
      now[ch0] = (now[ch0] + 1) * len + now[ch0];
      for (int i = 'a'; i <= 'z'; i++)
        if (ch0 != i) now[i] = max(min(now[i], 1ll), now1[i]);
    } else {
      now[ch0] = now1[ch0] + 1;
      now[ch1] = now1[ch1] + 1;
      for (int i = 'a'; i <= 'z'; i++)
        if (i != ch0 && ch1 != i) now[i] = max(min(now[i], 1ll), now1[i]);
    }
  }
  for (int i = 'a'; i <= 'z'; i++) Ans = max(Ans, now[i]);
  cout << Ans;
}
