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 + 5;
char x[maxn];
long long num[30], num1[30];
int main() {
  int n;
  scanf("%d", &n);
  for (int a = 0; a <= 27; a++) num[a] = 0, num1[a] = 0;
  scanf("%s", x);
  long long len = strlen(x);
  long long nu = 1;
  long long ans;
  for (int a = 1; a < len; a++) {
    if (x[a] == x[a - 1])
      nu++;
    else {
      num[x[a - 1] - 'a'] = max(num[x[a - 1] - 'a'], nu);
      nu = 1;
    }
  }
  num[x[len - 1] - 'a'] = max(num[x[len - 1] - 'a'], nu);
  for (long long a = 2; a <= n; a++) {
    long long fa = 0, son = 0, ans1 = 0;
    nu = 1;
    scanf("%s", x);
    len = strlen(x);
    for (int b = 1; b < len; b++) {
      if (x[b] == x[b - 1])
        nu++;
      else {
        if (fa == 0) fa = nu;
        num1[x[b - 1] - 'a'] = max(num1[x[b - 1] - 'a'], nu);
        nu = 1;
      }
    }
    son = nu;
    num1[x[len - 1] - 'a'] = max(num1[x[len - 1] - 'a'], nu);
    if (nu == len && fa == 0) {
      num1[x[0] - 'a'] = num[x[0] - 'a'] * (len + 1) + len;
    } else {
      int b, d;
      if (num[x[0] - 'a'] != 0) b = 1;
      if (num[x[len - 1] - 'a'] != 0) d = 1;
      if (x[0] == x[len - 1]) {
        num1[x[0] - 'a'] = max(fa + son + b, num1[x[0] - 'a']);
      } else {
        num1[x[0] - 'a'] = max(num1[x[0] - 'a'], fa + b);
        num1[x[len - 1] - 'a'] = max(num1[x[len - 1] - 'a'], son + d);
      }
    }
    for (int b = 0; b <= 27; b++) {
      if (num[b] != 0 && num1[b] == 0) num1[b] = 1;
      num[b] = num1[b];
      num1[b] = 0;
      ans1 = max(ans1, num[b]);
    }
    ans = ans1;
  }
  printf("%lld\n", ans);
}
