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;
const int INF = 0x3f3f3f3f;
const long long INF64 = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-8;
const int N = 1e5 + 10;
const int M = 1e5 + 10;
vector<long long> getCnt(string &s) {
  vector<long long> res(26);
  long long len = 1;
  for (int i = 0; i < s.size(); ++i) {
    int c = s[i];
    while (i + 1 < s.size() && s[i + 1] == c) {
      ++len;
      ++i;
    }
    res[c - 'a'] = max(res[c - 'a'], len);
    len = 1;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string prev;
  cin >> prev;
  vector<long long> &&mx = getCnt(prev);
  for (int i = 1; i < n; ++i) {
    string t;
    cin >> t;
    vector<long long> &&t_mx = getCnt(t);
    for (char c = 'a'; c <= 'z'; ++c) {
      int i = c - 'a';
      if (t_mx[i] == t.size()) {
        mx[i] = min((long long)INF, (long long)t.size() * (mx[i] + 1) + mx[i]);
      } else if (mx[i] > 0) {
        long long pref = 0, suff = 0;
        for (int j = 0; t[j] == c; ++j) ++pref;
        for (int j = t.size() - 1; t[j] == c; --j) ++suff;
        mx[i] = max(t_mx[i], pref + suff + 1);
      } else {
        mx[i] = t_mx[i];
      }
    }
  }
  long long ans = 0;
  for (auto i : mx) ans = max(ans, i);
  cout << ans << '\n';
  return 0;
}
