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;
string a[100000];
int n;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int res = 0, len = 0;
  for (char c = 'a'; c <= 'z'; c++) {
    len = 0;
    for (int i = 0; i < n; i++) {
      if (i == 0) {
        int cur = 0, mx = 0;
        for (int j = 0; j < a[i].size(); j++) {
          if (a[i][j] == c)
            cur++;
          else
            cur = 0;
          if (cur > mx) mx = cur;
        }
        len = mx;
        continue;
      }
      int cur = 0, mx = 0;
      for (int j = 0; j < a[i].size(); j++) {
        if (a[i][j] == c)
          cur++;
        else
          cur = 0;
        if (cur > mx) mx = cur;
      }
      if (mx == a[i].size()) {
        len = (len + 1) * mx + len;
      } else {
        int pref = 0, suf = 0;
        for (int j = 0; j < a[i].size(); j++) {
          if (a[i][j] == c)
            pref++;
          else
            break;
        }
        for (int j = (int)a[i].size() - 1; j >= 0; j--) {
          if (a[i][j] == c)
            suf++;
          else
            break;
        }
        if (len > 0)
          len = max(mx, pref + suf + 1);
        else
          len = max(mx, max(pref, suf));
      }
    }
    if (len > res) res = len;
  }
  cout << res << "\n";
  return 0;
}
