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 long long maxn = 1e5 + 7;
long long n, l;
char s[maxn];
long long len[30], tmp[30];
signed main() {
  scanf("%lld%s", &n, s + 1);
  l = strlen(s + 1);
  for (long long i = 1, lx = 0; i <= l; ++i) {
    ++lx;
    if (s[i] != s[i + 1]) len[s[i] - 'a'] = max(len[s[i] - 'a'], lx), lx = 0;
  }
  for (long long q = 1; q < n; ++q) {
    scanf("%s", s + 1);
    l = strlen(s + 1);
    memset(tmp, 0, sizeof(tmp));
    for (long long i = 1, lx = 0; i <= l; ++i) {
      ++lx;
      if (s[i] != s[i + 1]) tmp[s[i] - 'a'] = max(tmp[s[i] - 'a'], lx), lx = 0;
    }
    if (tmp[s[l] - 'a'] == l) {
      for (long long i = 0; i < 26; ++i) {
        if (i == s[l] - 'a')
          len[i] = min(len[i] * (l + 1) + l, 1000000000ll);
        else
          len[i] = min(len[i], 1ll);
      }
    } else {
      long long lc = s[1] - 'a', llen = 0, rc = s[l] - 'a', rlen = 0;
      while (s[llen + 1] - 'a' == lc) ++llen;
      while (s[l - rlen] - 'a' == rc) ++rlen;
      if (lc == rc) {
        for (long long i = 0; i < 26; ++i) {
          if (i == lc)
            len[i] = len[i] ? llen + rlen + 1 : 0;
          else
            len[i] = min(len[i], 1ll);
        }
      } else {
        for (long long i = 0; i < 26; ++i) {
          if (i == lc)
            len[i] = len[i] ? llen + 1 : 0;
          else if (i == rc)
            len[i] = len[i] ? rlen + 1 : 0;
          else
            len[i] = min(len[i], 1ll);
        }
      }
      for (long long i = 0; i < 26; ++i) len[i] = max(len[i], tmp[i]);
    }
  }
  long long ret = 0;
  for (long long i = 0; i < 26; ++i) ret = max(ret, len[i]);
  printf("%d\n", ret);
  return 0;
}
