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;
string str[100010];
int prefix, suffix;
int n;
bool mask[30];
int main() {
  int ans = 1;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> str[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < str[i].size(); j++) mask[str[i][j] - 'a'] |= 1;
  }
  int i = n - 1;
  prefix = suffix = 1;
  for (int j = 1; j < str[i].size(); j++) {
    if (str[i][j] != str[i][j - 1]) break;
    ++prefix;
  }
  for (int j = str[i].size() - 2; j >= 0; j--) {
    if (str[i][j] != str[i][j + 1]) break;
    ++suffix;
  }
  int first = str[i][0] - 'a';
  int last = str[i][str[i].size() - 1] - 'a';
  for (int j = 0; j < 26; j++) {
    if (!mask[j]) continue;
    if (j != first && j != last) continue;
    if (j == first && j == last)
      ans = max(ans, prefix + suffix + 1);
    else if (j == first)
      ans = max(ans, prefix + 1);
    else
      ans = max(ans, suffix + 1);
  }
  printf("%d\n", ans);
  return 0;
}
