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;
int n;
string str[100005];
int get(int id, char ch) {
  int len = str[id].size();
  if (id == 0) {
    int ans = 0, ct = 0;
    for (int i = 0; i < len; i++)
      if (str[id][i] == ch) {
        ct++;
        ans = max(ans, ct);
      } else
        ct = 0;
    return ans;
  }
  int f = 1;
  for (int i = 0; i < len; i++)
    if (str[id][i] != ch) {
      f = 0;
      break;
    }
  if (f == 1) {
    int ans = get(id - 1, ch);
    return ans + (ans + 1) * len;
  } else {
    int ans1 = 0, ans = 0;
    for (int i = 0; i < len; i++)
      if (str[id][i] == ch) {
        ans1++;
      } else
        break;
    int ans2 = 0;
    for (int i = len - 1; i >= 0; i--)
      if (str[id][i] == ch) {
        ans2++;
      } else
        break;
    ans = max(ans1, ans2);
    for (int i = 0; i < id; i++) {
      int tlen = str[i].size();
      for (int j = 0; j < tlen; j++) {
        if (str[i][j] == ch) {
          ans = ans1 + ans2 + 1;
          break;
        }
      }
    }
    int ct = 0;
    for (int i = 0; i < len; i++) {
      if (str[id][i] == ch) {
        ct++;
        ans = max(ans, ct);
      } else
        ct = 0;
    }
    return ans;
  }
}
int main() {
  while (~scanf("%d", &n)) {
    for (int i = 0; i < n; i++) cin >> str[i];
    int ans = 0;
    int len = str[n - 1].size();
    for (int i = 0; i < 26; i++) {
      ans = max(ans, get(n - 1, 'a' + i));
    }
    printf("%d\n", ans);
  }
  return 0;
}
