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 mx = 1e5 + 10;
string s[mx];
int fr(char a, int x) {
  int res = 0;
  for (int i = 0; i < s[x].size(); ++i) {
    if (s[x][i] == a)
      res++;
    else
      break;
  }
  return res;
}
int bk(char a, int x) {
  int res = 0;
  for (int i = s[x].size() - 1; i >= 0; --i) {
    if (s[x][i] == a)
      res++;
    else
      break;
  }
  return res;
}
int cal(char a, int x) {
  int res = 0;
  int maxn = -1;
  for (int i = 0; i < s[x].size(); ++i) {
    if (s[x][i] == a) {
      res++;
    } else {
      maxn = max(res, maxn);
      res = 0;
    }
  }
  maxn = max(res, maxn);
  return maxn;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }
  int ans = -1;
  for (int i = 0; i < 26; ++i) {
    int bef = 0;
    for (int j = 1; j <= n; ++j) {
      int f = fr('a' + i, j);
      int b = bk('a' + i, j);
      int mid = cal('a' + i, j);
      if (mid == s[j].size()) {
        bef = (bef + 1) * s[j].size() + bef;
      } else {
        bef = max(max(mid, bef > 0 ? f + b + 1 : max(b, f)), bef);
      }
    }
    ans = max(bef, ans);
  }
  printf("%d\n", ans);
}
