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;
using namespace chrono;
const int N = 26;
string s;
long long len[N];
int tmp[N];
int main() {
  time_point<steady_clock> start = steady_clock::now();
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    fill(tmp, tmp + N, 0);
    for (int j = 1, c = s[0], l = 1; j <= s.size(); j++) {
      if (j < s.size() && s[j] == s[j - 1])
        l++;
      else {
        tmp[c - 'a'] = max(tmp[c - 'a'], l);
        if (j < s.size()) {
          c = s[j];
          l = 1;
        }
      }
    }
    if (i == 1) {
      copy(tmp, tmp + N, len);
    } else {
      int pre = 1, suf = 1;
      for (int j = 1; j < s.size() && s[j] == s[0]; j++) pre++;
      for (int j = s.size() - 2; j >= 0 && s[j] == s.back(); j--) suf++;
      for (int j = 0; j < N; j++) {
        if (len[j]) {
          int cur = 1;
          if (s.back() == j + 'a') cur += suf;
          if (s.front() == j + 'a') cur += pre;
          len[j] = cur;
        }
      }
      for (int j = 0; j < N; j++) len[j] = max(len[j], 1LL * tmp[j]);
    }
  }
  long long ans = 0;
  for (int i = 0; i < N; i++) ans = max(ans, len[i]);
  cout << ans << endl;
  cerr << endl
       << "------------------------------" << endl
       << "Time: "
       << duration<double, milli>(steady_clock::now() - start).count() << " ms."
       << endl;
  return 0;
}
