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;
char ss[100005];
int a[30], b[30], p1, p2;
int len;
void upd(int &x, int y) { x = max(x, y); }
void calc() {
  memset(a, 0, sizeof a);
  len = strlen(ss + 1);
  p1 = 0;
  p2 = 0;
  p1 = 1;
  while (p1 < len && ss[p1 + 1] == ss[1]) p1++;
  p2 = 1;
  while (p2 < len && ss[len - p2] == ss[len]) p2++;
  for (int i = 1, cc = 1; i < len; i++) {
    if (ss[i] != ss[i + 1])
      upd(a[ss[i] - 'a' + 1], cc), cc = 1;
    else
      cc++;
  }
  upd(a[ss[len] - 'a' + 1], p2);
}
int main() {
  scanf("%d", &n);
  scanf("%s", &ss[1]);
  calc();
  for (int i = 1; i <= 26; i++) b[i] = a[i];
  for (int i = 1; i < n; i++) {
    scanf("%s", &ss[1]);
    calc();
    if (p1 == len) {
      int x = ss[1] - 'a' + 1;
      b[x] = a[x] * b[x] + b[x] + a[x];
      for (int j = 1; j <= 26; j++) {
        if (j == x) continue;
        if (b[j])
          b[j] = 1;
        else
          b[j] = 0;
      }
    } else if (ss[1] == ss[len]) {
      int x = ss[1] - 'a' + 1;
      if (b[x]) b[x] = p1 + p2 + 1;
      for (int j = 1; j <= 26; j++) {
        if (j == x) continue;
        if (b[j])
          b[j] = 1;
        else
          b[j] = 0;
      }
    } else {
      int x = ss[1] - 'a' + 1;
      int y = ss[len] - 'a' + 1;
      if (b[x]) b[x] = p1 + 1;
      if (b[y]) b[y] = p2 + 1;
      for (int j = 1; j <= 26; j++) {
        if (j == x || j == y) continue;
        if (b[j])
          b[j] = 1;
        else
          b[j] = 0;
      }
    }
    for (int i = 1; i <= 26; i++) upd(b[i], a[i]);
  }
  int orz = 0;
  for (int i = 1; i <= 26; i++) {
    orz = max(orz, b[i]);
  }
  printf("%d", orz);
}
