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;
long long n, mx[256], aux[256], ans = 0, inf = 1e9;
string s;
void count(long long mx[]) {
  long long in = 0, cn = 0;
  for (int c : s) {
    if (in != c) {
      mx[in] = max(mx[in], cn);
      in = c;
      cn = 0;
    }
    cn++;
  }
  mx[in] = max(mx[in], cn);
}
void update() {
  cin >> s;
  long long pre = 0, suf = 0;
  for (int i = 0; i < s.size() && s[0] == s[i]; i++) pre++;
  for (int i = s.size() - 1; i + 1 && s.back() == s[i]; i--) suf++;
  if (pre == s.size()) {
    for (int i = 'a'; i <= 'z'; i++)
      if (i == s[0]) {
        mx[i] = mx[i] + pre * (mx[i] + 1);
      } else {
        mx[i] = int(mx[i] > 1);
      }
  } else {
    memset(aux, 0, sizeof(aux));
    if (s[0] == s.back()) {
      if (mx[s[0]]) aux[s[0]] = suf + pre + 1;
    } else {
      aux[s[0]] = pre + int(mx[s[0]] > 1);
      aux[s.back()] = suf + int(mx[s.back()] > 1);
    }
    count(aux);
    for (int i = 'a'; i <= 'z'; i++)
      mx[i] = max((long long)(mx[i] > 0), aux[i]);
  }
  for (int i = 'a'; i <= 'z'; i++) mx[i] = min(mx[i], inf);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> s;
  count(mx);
  n--;
  while (n--) update();
  for (int i = 'a'; i <= 'z'; i++) ans = max(ans, mx[i]);
  cout << ans << '\n';
  return 0;
}
