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;
inline long long read() {
  long long x = 0;
  int ch = getchar(), f = 1;
  while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 1e5 + 10;
int T, n, Max[26];
char s[N];
int main() {
  T = read(), scanf("%s", s + 1), n = strlen(s + 1);
  int x = 1;
  for (register int i = (1); i <= (n); i++)
    if (i == n || s[i] != s[i + 1])
      Max[s[i] - 'a'] = max(Max[s[i] - 'a'], x), x = 1;
    else
      x++;
  for (register int i = (2); i <= (T); i++) {
    scanf("%s", s + 1), n = strlen(s + 1);
    int l = 1, r = n, lc = s[1] - 'a', rc = s[n] - 'a';
    while (l < n && s[l + 1] == s[l]) l++;
    while (r > 1 && s[r - 1] == s[r]) r--;
    for (register int i = (0); i <= (25); i++)
      if (i != lc && i != rc) Max[i] = (Max[i] > 0);
    if (l == n)
      Max[lc] = n * (Max[lc] + 1) + Max[lc];
    else if (s[1] == s[n])
      Max[lc] = max(Max[lc], l + (n - r + 1) + 1);
    else
      Max[lc] = max(Max[lc], l + (Max[lc] > 0)),
      Max[rc] = max(Max[rc], (n - r + 1) + (Max[rc] > 0));
    int x = 1;
    for (register int i = (1); i <= (n); i++)
      if (i == n || s[i] != s[i + 1])
        Max[s[i] - 'a'] = max(Max[s[i] - 'a'], x), x = 1;
      else
        x++;
  }
  int ans = 0;
  for (register int i = (0); i <= (25); i++) ans = max(ans, Max[i]);
  printf("%d\n", ans);
}
