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 size_t N = 1e5 + 5;
const int AL = 26;
int mx[AL], nw[AL];
void chkmax(int &dp, int val) {
  if (val > dp) dp = val;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    static char s[N];
    scanf("%s", s);
    int n = strlen(s);
    int cur = 1;
    if (!i) chkmax(nw[s[0] - 'a'], 1);
    for (int i = 1; i < n; ++i) {
      if (s[i] == s[i - 1]) {
        ++cur;
      } else {
        cur = 1;
      }
      if (!i) chkmax(nw[s[i] - 'a'], cur);
      chkmax(nw[s[i] - 'a'], 1);
    }
    if (cur == n) {
      chkmax(nw[s[0] - 'a'], (n + 1) * (mx[s[0] - 'a'] + 1) - 1);
    }
    for (int i = 0; i < AL; ++i) {
      if (!mx[i]) continue;
      int j = 0, k = n - 1;
      for (; j < n && s[j] == i + 'a'; ++j) {
      }
      for (; k >= 0 && s[k] == i + 'a'; --k) {
      }
      chkmax(nw[i], n + j - k);
    }
    memcpy(mx, nw, sizeof mx);
  }
  int ans = 0;
  for (int i = 0; i < AL; ++i) chkmax(ans, mx[i]);
  cout << ans;
  return 0;
}
