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>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void redirectIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
vector<long long> getLengts(const string& s) {
  vector<long long> lengths(26);
  int cur = -1;
  int len = -1;
  for (char c : s) {
    int now = c - 'a';
    len++;
    if (now != cur) {
      cur = now;
      len = 1;
    }
    lengths[cur] = max(lengths[cur], (long long)len);
  }
  return lengths;
}
int main() {
  redirectIO();
  int n;
  cin >> n;
  string p;
  cin >> p;
  vector<long long> lengths = getLengts(p);
  for (int j = 0; j < (n - 1); j++) {
    string s;
    cin >> s;
    int suff = s.back() - 'a';
    int slen = 1;
    for (int i = (int)s.length() - 2; i >= 0 && s[i] == s.back(); i--) {
      slen++;
    }
    int pref = s[0] - 'a';
    int plen = 1;
    for (int i = 1; i < s.length() && s[i] == s[0]; i++) {
      plen++;
    }
    vector<long long> curLengths = getLengts(s);
    if (plen == s.length()) {
      for (int i = 0; i < (26); i++) {
        if (i == pref) {
          lengths[i] = lengths[i] + (lengths[i] + 1) * curLengths[i];
        } else
          lengths[i] = min(lengths[i], 1LL);
      }
    } else {
      for (int i = 0; i < (26); i++) {
        if (lengths[i] > 0) {
          lengths[i] = 1 + (pref == i) * plen + (suff == i) * slen;
        }
        lengths[i] = max(lengths[i], curLengths[i]);
      }
    }
    for (int i = 0; i < (26); i++)
      if (lengths[i] > 2e9) lengths[i] = 2e9;
  }
  long long ans = 0;
  for (long long x : lengths) ans = max(ans, x);
  cout << ans << endl;
  return 0;
}
