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;
using ll = long long;
using ii = pair<int, int>;
const int N = 100005;
vector<string> second;
int solve(int id, char c, int x) {
  if (id == (int)second.size()) return x;
  int cnt = 0;
  int maxi = 0;
  for (char i : second[id]) {
    if (i == c)
      cnt++;
    else
      cnt = 0;
    maxi = max(maxi, cnt);
  }
  if (maxi == (int)second[id].size()) {
    return solve(id + 1, c, (x + 1) * maxi + x);
  } else {
    int pre = 0, suf = 0;
    while (second[id][pre] == c) pre++;
    while (second[id][(int)second[id].size() - suf - 1] == c) suf++;
    if (x) return solve(id + 1, c, max(maxi, suf + 1 + pre));
    return solve(id + 1, c, maxi);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  char s[N];
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    second.push_back(s);
  }
  int ans = 1;
  for (char i = 'a'; i <= 'z'; i++) {
    ans = max(ans, solve(0, i, 0));
  }
  printf("%d\n", ans);
  return 0;
}
