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 N = 100010;
int pref(const string& s, int c) {
  int i = 0;
  while (i < s.size() and s[i] == c) i++;
  return i;
}
int suf(const string& s, int c) {
  int i = (int)s.size() - 1;
  while (i >= 0 and s[i] == c) i--;
  return (int)s.size() - 1 - i;
}
int beauty(const string& s, int c) {
  int i = 0, ret = 0, b = 0;
  while (i < s.size()) {
    if (s[i] == c)
      b++;
    else
      b = 0;
    ret = max(ret, b);
    i++;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> p;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    p.push_back(s);
  }
  int ans = 0;
  for (int l = 'a'; l <= 'z'; l++) {
    int b = beauty(p[0], l);
    for (int i = 1; i < n; i++) {
      int sum = pref(p[i], l) + suf(p[i], l);
      if (sum == 2 * p[i].size())
        b += (b + 1) * (int)p[i].size();
      else {
        if (b > 0)
          b = max(beauty(p[i], l), sum + 1);
        else
          b = beauty(p[i], l);
      }
    }
    ans = max(ans, b);
  }
  cout << ans << '\n';
  return 0;
}
