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 maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n;
long long mx[26], ans;
vector<pair<int, int> > getlens(string s) {
  vector<pair<int, int> > ret;
  for (int i = 0; i < (int)s.size(); i++) {
    int j = i;
    while (j + 1 < (int)s.size() && s[j + 1] == s[i]) ++j;
    ret.push_back(pair<int, int>(s[i] - 'a', j - i + 1));
    i = j;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    vector<pair<int, int> > cur = getlens(s);
    pair<int, int> pref = cur[0], suf = cur.back();
    if ((int)cur.size() == 1) {
      for (int le = 0; le < 26; le++) {
        if (le != pref.first)
          mx[le] = min(mx[le], 1ll);
        else
          mx[le] += pref.second * (mx[le] + 1);
      }
    } else {
      for (int le = 0; le < 26; le++) {
        if (pref.first == suf.first) {
          if (le == pref.first) mx[le] = pref.second + suf.second + 1;
        } else {
          if (le == pref.first) mx[le] = 1 + pref.second;
          if (le == suf.first) mx[le] = 1 + suf.second;
        }
        if (le != suf.first && le != pref.first) mx[le] = min(mx[le], 1ll);
      }
      for (pair<int, int> aa : cur)
        mx[aa.first] = max(mx[aa.first], (long long)aa.second);
    }
    for (int le = 0; le < 26; le++) mx[le] = min(mx[le], (long long)mod);
  }
  for (int le = 0; le < 26; le++) ans = max(ans, mx[le]);
  cout << ans << "\n";
  return 0;
}
