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 main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<long long> cnt(26);
  string s;
  for (int ss = 0; ss < (int)n; ss++) {
    cin >> s;
    for (int i = 0; i < (int)s.size(); i++) s[i] -= 'a';
    int nfst = 0, nlst = 0;
    while (nfst < s.size() && s[nfst] == s[0]) nfst++;
    while (nlst < s.size() && s[s.size() - nlst - 1] == s.back()) nlst++;
    vector<long long> old(cnt);
    fill(cnt.begin(), cnt.end(), 0);
    for (int i = 0; i < (int)26; i++) cnt[i] = old[i] > 0;
    if (nfst == s.size())
      cnt[s[0]] = (old[s[0]] + 1) * nfst + old[s[0]];
    else if (s[0] == s.back()) {
      if (old[s[0]]) cnt[s[0]] = nfst + 1 + nlst;
    } else {
      if (old[s[0]]) cnt[s[0]] = nfst + 1;
      if (old[s.back()]) cnt[s.back()] = 1 + nlst;
    }
    char cur = s[0];
    long long streak = 1;
    cnt[cur] = max(cnt[cur], streak);
    for (int i = 1; i < s.size(); i++) {
      if (s[i] == cur)
        streak++;
      else {
        cur = s[i];
        streak = 1;
      }
      cnt[cur] = max(cnt[cur], streak);
    }
    for (int i = 0; i < (int)26; i++) cnt[i] = min(cnt[i], (long long)1e9);
  }
  long long ans = 0;
  for (int i = 0; i < (int)26; i++) ans = max(ans, cnt[i]);
  cout << ans << "\n";
}
