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;
bool isrange(int second, int first, int n, int m) {
  if (0 <= second && second < n && 0 <= first && first < m) return true;
  return false;
}
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},
    ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MAX = 101010;
string arr[MAX];
int ans = 0;
int ck[26];
int main(void) {
  int n;
  scanf("%d", &n);
  for (int e = 0; e < n; e++) cin >> arr[e];
  int ll = 1;
  for (int e = 1; e < (int)arr[0].size(); e++) {
    if (arr[0][e] != arr[0][e - 1]) {
      ck[arr[0][e - 1] - 'a'] = max(ck[arr[0][e - 1] - 'a'], ll);
      ll = 0;
    }
    ll++;
  }
  ck[arr[0][(int)arr[0].size() - 1] - 'a'] =
      max(ck[arr[0][(int)arr[0].size() - 1] - 'a'], ll);
  for (int e = 1; e < n; e++) {
    int ck2[26];
    for (int p = 0; p < 26; p++) {
      if (ck[p])
        ck2[p] = 1;
      else
        ck2[p] = 0;
    }
    bool suc = false;
    int wh = arr[e][0] - 'a';
    for (int p = 1; p < (int)arr[e].size(); p++) {
      if (arr[e][p] != arr[e][p - 1]) suc = true;
    }
    if (!suc) {
      ck2[wh] = (ck[wh] + 1) * ((int)arr[e].size() + 1) - 1;
    } else {
      int ll = 1, rr = 1;
      char a = arr[e][0], b = arr[e][(int)arr[e].size() - 1];
      for (int p = 1; p < (int)arr[e].size(); p++) {
        if (arr[e][p] != arr[e][p - 1]) break;
        ll++;
      }
      for (int p = (int)arr[e].size() - 2; p >= 0; p--) {
        if (arr[e][p] != arr[e][p + 1]) break;
        rr++;
      }
      int f1 = a - 'a';
      int f2 = b - 'a';
      ck2[f1] += ll;
      ck2[f2] += rr;
    }
    int ll = 1;
    for (int p = 1; p < (int)arr[e].size(); p++) {
      if (arr[e][p] != arr[e][p - 1]) {
        ck2[arr[e][p] - 'a'] = max(ck2[arr[e][p] - 'a'], ll);
        ll = 0;
      }
      ll++;
    }
    ck2[arr[e][(int)arr[e].size() - 1] - 'a'] =
        max(ck2[arr[e][(int)arr[e].size() - 1] - 'a'], ll);
    for (int e = 0; e < 26; e++) ck[e] = ck2[e];
  }
  for (int e = 0; e < 26; e++) ans = max(ans, ck[e]);
  printf("%d", ans);
  return 0;
}
