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 n;
const int N = 100010;
string s[N];
int ans;
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }
  for (char c = 'a'; c <= 'z'; ++c) {
    int mxlen = 0;
    bool hav = 0;
    for (int i = 1; i <= n; ++i) {
      bool fl = 1;
      for (int j = 0; j < s[i].size(); ++j)
        if (s[i][j] != c) fl = 0;
      int cnt = 0, bb = 0;
      for (int j = 0; j < s[i].size(); ++j) {
        if (s[i][j] == c)
          ++bb;
        else
          bb = 0;
        cnt = max(cnt, bb);
      }
      if (fl) {
        long long t;
        t = mxlen + (long long)(mxlen + 1) * s[i].size();
        if (t > 1e9)
          mxlen = 1e9;
        else
          mxlen = t;
      } else {
        int p = s[i].size() - 1, fi = 0, la = 0;
        while (s[i][p] == c) --p, ++la;
        p = 0;
        while (s[i][p] == c) ++p, ++fi;
        mxlen = (hav ? fi + la + 1 : 0);
      }
      for (int j = 0; j < s[i].size(); ++j) hav |= (s[i][j] == c);
      mxlen = max(mxlen, cnt);
    }
    ans = max(ans, mxlen);
  }
  cout << ans;
}
