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 = 1e5 + 5;
string P[N];
bitset<26> bs[N];
int FindMax(int n, char c) {
  int l = P[n].length();
  int cnt = 0, mx = 0;
  int pre = -1, suff = -1;
  for (int i = 0; i < l; i++) {
    if (P[n][i] == c) {
      cnt++;
      mx = max(mx, cnt);
    } else {
      if (pre == -1) pre = cnt;
      cnt = 0;
    }
  }
  suff = cnt;
  if (n == 1) {
    return mx;
  }
  if (cnt == l) {
    int m = FindMax(n - 1, c);
    return (m + 1) * l + m;
  } else {
    int m = FindMax(n - 1, c);
    if (m) {
      mx = max(mx, suff + 1 + pre);
    }
    return mx;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> P[i];
  }
  int ans = 0;
  for (char c = 'a'; c <= 'z'; c++) {
    ans = max(ans, FindMax(n, c));
  }
  cout << ans << "\n";
  return 0;
}
