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 d[30];
char sir[100010];
int main() {
  int n, sol = 1;
  scanf("%d\n", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s\n", sir + 1);
    int l = strlen(sir + 1);
    if (i != 1) {
      int nr2 = 1;
      for (int i = l - 1; l >= 1; i--)
        if (sir[i] == sir[i + 1])
          nr2++;
        else
          break;
      int nr1 = 1;
      for (int i = 2; i <= l; i++)
        if (sir[i] == sir[i - 1])
          nr1++;
        else
          break;
      if (sir[1] == sir[l]) {
        if (nr1 != nr2) {
          if (d[sir[1] - 'a'] > 0) {
            d[sir[1] - 'a'] = max(d[sir[1] - 'a'], nr1 + nr2 + 1);
            if (i == n) sol = max(sol, nr1 + nr2 + 1);
          }
        } else {
          if (d[sir[1] - 'a'] > 0) {
            d[sir[1] - 'a'] = l * (d[sir[1] - 'a'] + 1) + d[sir[1] - 'a'];
            if (i == n) sol = max(sol, d[sir[1] - 'a']);
          }
        }
      } else {
        if (d[sir[1] - 'a'] > 0) {
          d[sir[1] - 'a'] = max(d[sir[1] - 'a'], nr1 + 1);
          if (i == n) sol = max(sol, nr1 + 1);
        }
        if (d[sir[l] - 'a'] > 0) {
          d[sir[l] - 'a'] = max(d[sir[l] - 'a'], nr2 + 1);
          if (i == n) sol = max(sol, nr2 + 1);
        }
      }
    }
    int nr = 1;
    char a = sir[1];
    for (int i = 2; i <= l; i++)
      if (sir[i] == a)
        nr++;
      else {
        d[a - 'a'] = max(d[a - 'a'], nr);
        if (i == n) sol = max(sol, nr);
        a = sir[i];
        nr = 1;
      }
    d[a - 'a'] = max(d[a - 'a'], nr);
    if (i == n) sol = max(sol, nr);
  }
  printf("%d", sol);
  return 0;
}
