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 N = 100010;
const long long mod = 1000000007;
int cnt[30], vis[30];
char s[100004];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int cur[30] = {};
    scanf("%s", s);
    int len = strlen(s);
    int pre = 0, sum = 0, l = 0, r = 0;
    for (int j = 0; j < len; j++) {
      if (s[j] - 'a' + 1 == pre) {
        sum++;
        cur[pre] = max(cur[pre], sum);
      } else {
        cur[pre] = max(cur[pre], sum);
        sum = 1;
        pre = s[j] - 'a' + 1;
      }
    }
    pre = s[0] - 'a' + 1;
    for (int j = 0; j < len; j++) {
      if (pre == s[j] - 'a' + 1)
        l++;
      else
        break;
    }
    pre = s[len - 1] - 'a' + 1;
    for (int j = len - 1; j >= 0; j--) {
      if (pre == s[j] - 'a' + 1)
        r++;
      else
        break;
    }
    if (l == len) {
      cnt[s[0] - 'a' + 1] =
          (cnt[s[0] - 'a' + 1] + 1) * len + cnt[s[0] - 'a' + 1];
    } else {
      if (s[len - 1] == s[0]) {
        if (vis[s[0] - 'a' + 1]) cnt[s[0] - 'a' + 1] = l + r + 1;
      } else {
        cnt[s[0] - 'a' + 1] = l + vis[s[0] - 'a' + 1];
        cnt[s[len - 1] - 'a' + 1] = r + vis[s[len - 1] - 'a' + 1];
      }
    }
    for (int j = 0; j < 30; j++) {
      if (j == s[0] - 'a' + 1 || s[len - 1] - 'a' + 1 == j)
        cnt[j] = max(cnt[j], cur[j]);
      else
        cnt[j] = max(vis[j], cur[j]);
    }
    for (int j = 0; j < len; j++) vis[s[j] - 'a' + 1] = 1;
  }
  int mx = 0;
  for (int i = 0; i < 30; i++) {
    mx = max(mx, cnt[i]);
  }
  printf("%d\n", mx);
  return 0;
}
