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;
inline void rd(int &x) {
  char ch;
  x = 0;
  bool fl = false;
  while (!isdigit(ch = getchar())) (ch == '-') && (fl = true);
  for (x = (ch ^ '0'); isdigit(ch = getchar()); x = x * 10 + (ch ^ '0'))
    ;
  (fl == true) && (x = -x);
}
namespace Miracle {
const int N = 100000 + 5;
int n;
char s[N];
int m;
int len[28];
int tmp[28];
int pr, tpr;
int bc, tbc;
int num(char ch) { return ch - 'a'; }
int main() {
  rd(n);
  for (register int i = 1; i <= n; ++i) {
    scanf("%s", s + 1);
    m = strlen(s + 1);
    memset(tmp, 0, sizeof tmp);
    tpr = s[1] - 'a', tbc = s[m] - 'a';
    pr = 0;
    bc = 0;
    int p = 1;
    while (p <= m && num(s[p]) == tpr) {
      ++pr;
      ++p;
    }
    tmp[tpr] = pr;
    int ls = 0;
    for (; p <= m; ++p) {
      int now = num(s[p]);
      ls = 0;
      while (p <= m && num(s[p]) == now) {
        ++ls;
        ++p;
      }
      tmp[now] = max(tmp[now], ls);
    }
    bc = ls;
    for (register int c = 0; c < 26; ++c) {
      if (!len[c]) {
        len[c] = tmp[c];
      } else {
        if (c == tpr && c == tbc) {
          if (pr == m) {
            len[c] = len[c] + (len[c] + 1) * m;
          } else {
            len[c] = 1 + pr + bc;
          }
        } else if (c == tpr) {
          len[c] = 1 + pr;
        } else if (c == tbc) {
          len[c] = 1 + bc;
        } else {
          len[c] = max(1, tmp[c]);
        }
      }
    }
  }
  int ans = 0;
  for (register int i = 0; i < 26; ++i) {
    ans = max(ans, len[i]);
  }
  cout << ans;
  return 0;
}
}  // namespace Miracle
signed main() {
  Miracle::main();
  return 0;
}
