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 i, j, cnt = 0;
int ar[26] = {0};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  while (n--) {
    string s;
    cin >> s;
    int len = s.length();
    for (i = 0; i < len; i++)
      if (s[i] != s[0]) break;
    if (i == len) {
      ar[s[0] - 'a'] = ar[s[0] - 'a'] * len + ar[s[0] - 'a'] + len;
      for (i = 0; i < 26; i++) {
        if (i != s[0] - 'a') ar[i] = min(ar[i], 1);
      }
    } else {
      for (i = 0; i < 26; i++) {
        ar[i] = min(ar[i], 1);
      }
      int fr = 0, la = len - 1;
      for (fr = 0; fr < len; fr++)
        if (s[i] != s[0]) break;
      for (la = len - 1; la >= 0; la--)
        if (s[i] != s[len - 1]) break;
      if (s[0] == s[len - 1]) {
        if (ar[s[0] - 'a'] == 1) ar[s[0] - 'a'] = fr + len - la;
      } else {
        if (ar[s[0] - 'a'] == 1) ar[s[0] - 'a'] = fr + 1;
        if (ar[s[len - 1] - 'a'] == 1) ar[s[len - 1] - 'a'] = 1 + len - la;
      }
      int now = fr;
      for (i = fr; i < la + 1; i++) {
        if (s[i] == s[now])
          cnt++;
        else
          cnt = 1, now = i;
        ar[s[now] - 'a'] = max(cnt, ar[s[now] - 'a']);
      }
    }
  }
  cout << (int)(*max_element(ar, ar + 26)) << '\n';
  return ~~(0 ^ 0 ^ 0);
}
