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;
int n, lim, len, a[100005], pre, las, f[30], g[30], ans, s[30], cnt;
char ch[100005];
int gets() {
  int v = 0;
  bool f = 0;
  char ch;
  while (!isdigit(ch)) {
    f |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    v = (v << 3) + (v << 1) + ch - 48;
    ch = getchar();
  }
  return f ? -v : v;
}
void work() {
  for (int i = 1; i <= 26; i++) {
    g[i] = f[i];
    f[i] = 0;
    if (a[1] == i) {
      if (pre == len) {
        f[i] = g[i] + len * (g[i] + 1);
      } else if (a[len] == i) {
        f[i] = pre + las + 1;
      } else {
        f[i] = pre;
        if (g[i] > 0) f[i]++;
      }
    } else if (a[len] == i) {
      f[i] = las;
      if (g[i] > 0) f[i]++;
    } else {
      if (g[i] > 0) f[i] = 1;
    }
    f[i] = max(f[i], s[i]);
  }
}
int main() {
  n = gets();
  lim = 26;
  for (int i = 1; i <= n; i++) {
    scanf("%s", ch + 1);
    len = strlen(ch + 1);
    for (int j = 1; j <= lim; j++) s[j] = 0;
    for (int j = 1; j <= len; j++) a[j] = ch[j] + 1 - 'a';
    pre = las = 1;
    for (int j = 2; j <= len; j++)
      if (a[j] == a[j - 1])
        pre++;
      else
        break;
    for (int j = len - 1; j >= 1; j--)
      if (a[j] == a[j + 1])
        las++;
      else
        break;
    cnt = 1;
    a[len + 1] = 0;
    for (int j = 2; j <= len; j++) {
      if (a[j] != a[j - 1]) {
        s[a[j - 1]] = max(s[a[j - 1]], cnt);
        cnt = 1;
      } else
        cnt++;
    }
    s[a[len]] = max(s[a[len]], cnt);
    work();
  }
  for (int j = 1; j <= lim; j++) ans = max(ans, f[j]);
  printf("%d\n", ans);
  return 0;
}
