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>
#pragma GCC optimize(2)
using namespace std;
void qread(int &x) {
  int neg = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = 10 * x + c - '0', c = getchar();
  x *= neg;
}
const int maxn = 100005;
int n, m;
char c[maxn];
int val[26];
int main() {
  scanf("%d", &n);
  for (int(i) = 0; (i) < n; i++) {
    scanf("%s", c);
    m = strlen(c);
    for (int(z) = 0; (z) < 26; z++) {
      int l = 0, r = 0, mx = 0, cnt = 0;
      while (l < m && c[l] - 'a' == z) l++;
      while (r < m && c[m - 1 - r] - 'a' == z) r++;
      for (int(j) = 0; (j) < m; j++) {
        if (c[j] - 'a' == z)
          cnt++;
        else
          cnt = 0;
        mx = max(mx, cnt);
      }
      if (mx != m) {
        int old = val[z];
        val[z] = mx;
        if (old) val[z] = max(val[z], r + l + 1);
      } else {
        val[z] = (val[z] + 1) * m + val[z];
      }
    }
  }
  int ans = 0;
  for (int(z) = 0; (z) < 26; z++) ans = max(ans, val[z]);
  printf("%d\n", ans);
  return 0;
}
