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 a[100005], f[30], p[30];
int n, d, c;
string s;
void tinh() {
  for (int i = 1; i <= 26; i++) {
    if (i != a[1] && i != a[n]) {
      if (f[i] > 1) f[i] = 1;
      f[i] = max(f[i], p[i]);
      continue;
    }
    if (i == a[1] && i == a[n]) {
      if (d == n)
        f[i] = f[i] + (f[i] + 1) * n;
      else
        f[i] = d + c + 1;
      continue;
    }
    if (i == a[1]) {
      if (f[i] == 0)
        f[i] = d;
      else
        f[i] = d + 1;
      continue;
    }
    if (i == a[n]) {
      if (f[i] == 0)
        f[i] = c;
      else
        f[i] = c + 1;
      continue;
    }
  }
}
void them() {
  n = s.length();
  a[n + 1] = 0;
  a[0] = 0;
  for (int i = 1; i <= n; i++) a[i] = int(s[i - 1]) - int('a') + 1;
  for (int i = 1; i <= 26; i++) p[i] = 0;
  int sl = 1;
  for (int i = 2; i <= n + 1; i++)
    if (a[i] == a[i - 1])
      sl++;
    else {
      p[a[i - 1]] = max(p[a[i - 1]], sl);
      sl = 1;
    }
  for (int i = 2; i <= n + 1; i++)
    if (a[i] != a[i - 1]) {
      d = i - 1;
      break;
    }
  for (int i = n - 1; i >= 0; i--)
    if (a[i] != a[i + 1]) {
      c = n - i;
      break;
    }
  tinh();
}
void nhap() {
  int test;
  cin >> test;
  for (int i = 1; i <= test; i++) {
    cin >> s;
    them();
  }
}
void xuat() {
  int kq = 0;
  for (int i = 1; i <= 26; i++) kq = max(kq, f[i]);
  cout << kq;
}
int main() {
  nhap();
  xuat();
}
