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>
const int maxN = 100005;
const long long lim = 1e9 + 5;
int n, m;
long long ans, f[26];
std::string str;
bool o[maxN];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  for (int i = 1, l, r, x; i <= n; i++) {
    std::cin >> str;
    m = (int)str.size();
    str = " " + str;
    l = r = 0;
    for (int j = 1; j <= m; j++) {
      if (str[1] == str[j]) {
        l++;
      } else {
        break;
      }
    }
    for (int j = m; j >= 1; j--) {
      if (str[m] == str[j]) {
        r++;
      } else {
        break;
      }
    }
    for (int k = 0; k < 26; k++) {
      x = 0;
      for (int j = 1, lst = 0; j <= m; j++) {
        if (str[j] - 'a' == k) {
          x = std::max(x, j - lst);
        } else {
          lst = j;
        }
      }
      if (l == m && str[1] - 'a' == k) {
        f[k] = f[k] + (f[k] + 1) * m;
      } else {
        if (o[k]) {
          f[k] =
              (str[1] - 'a' == k ? l : 0) + (str[m] - 'a' == k ? r : 0) + o[k];
        } else {
          f[k] = o[k];
        }
      }
      f[k] = std::min(std::max(f[k], (long long)x), lim);
      for (int j = 1; j <= m; j++) {
        if (str[j] - 'a' == k) {
          o[k] = true;
        }
      }
    }
  }
  for (int i = 0; i < 26; i++) {
    ans = std::max(ans, f[i]);
  }
  std::cout << ans;
  return 0;
}
