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;
const long long inff = 0x3f3f3f3f3f3f3f3f;
int n, dp[100008][28], h, t, ddp, l;
char a[100008];
int main() {
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int kk(1); kk <= (n); ++kk) {
    scanf("%s", a);
    int zz = 1, k, qw = 0;
    h = k = a[0] - 'a';
    l = strlen(a);
    t = a[l - 1] - 'a';
    int q, w, er = 0;
    for (int i(1); i <= (l - 1); ++i) {
      if ((a[i] - 'a') == k)
        zz++;
      else {
        if (!er) er = 1, q = zz;
        dp[kk][k] = max(dp[kk][k], zz), k = (a[i] - 'a'), zz = 1;
      }
    }
    dp[kk][k] = max(dp[kk][k], zz);
    w = zz;
    for (int i(0); i <= (25); ++i)
      if (dp[kk][i] == l) qw = 1;
    for (int i(0); i <= (25); ++i)
      if (dp[kk - 1][i] && !dp[kk][i]) dp[kk][i] = 1;
    if (qw) {
      dp[kk][k] = (dp[kk - 1][k] + 1) * l + dp[kk - 1][k];
      continue;
    }
    if (h == t) {
      if (dp[kk - 1][t]) dp[kk][t] = max(dp[kk][t], q + w + 1);
      continue;
    }
    if (dp[kk - 1][h]) dp[kk][h] = max(dp[kk][h], q + 1);
    if (dp[kk - 1][t]) dp[kk][t] = max(dp[kk][t], w + 1);
  }
  int ans = 0;
  for (int i(0); i <= (25); ++i) ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}
