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 len[26], n;
bool seen[26];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    string s;
    cin >> s;
    int cnt[26] = {};
    for (auto &c : s) ++cnt[c - 'a'];
    if (accumulate(cnt, cnt + 26, 0) == 1) {
      for (int j = 0; j < 26; ++j)
        if (s[0] != j + 'a')
          len[j] = !!len[j];
        else
          len[j] = len[j] * (s.size() + 1) + s.size();
    } else {
      for (int j = 0; j < 26; ++j) len[j] = !!len[j];
      if (len[s[0] - 'a']) {
        long long now = 1;
        for (int j = 0; s[j++] == s[0]; ++now)
          ;
        for (int j = s.size(); s[--j] == s[0]; ++now)
          ;
        len[s[0] - 'a'] = max(len[s[0] - 'a'], now);
      }
      if (len[s.back() - 'a']) {
        long long now = 1;
        for (int j = 0; s[j++] == s.back(); ++now)
          ;
        for (int j = s.size(); s[--j] == s.back(); ++now)
          ;
        len[s.back() - 'a'] = max(len[s.back() - 'a'], now);
      }
      for (long long i = 0, j; i < s.size(); i = j) {
        for (j = i; j < s.size() && s[j] == s[i]; ++j)
          ;
        len[s[i] - 'a'] = max(len[s[i] - 'a'], j - i);
      }
    }
    for (int j = 0; j < 26; ++j) len[j] = min(len[j], (long long)1e9 + 7);
    for (int j = 0; j < 26; ++j) seen[j] = !!cnt[j];
  }
  cout << *max_element(len, len + 26);
}
