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;
long long power(long long a, long long p) {
  if (p == 0) return 1;
  if (p == 1) return a;
  long long tmp = power(a, p / 2);
  if (p % 2)
    tmp = ((tmp * tmp) % 1000000007) * a;
  else
    tmp *= tmp;
  return tmp % 1000000007;
}
long long NUM;
char C;
bool TURN;
long long uf() {
  NUM = 0;
  C = getchar();
  TURN = false;
  while ((C > '9' || C < '0') && C != '-') C = getchar();
  while ((C <= '9' && C >= '0') || C == '-') {
    if (C == '-')
      TURN = true;
    else
      NUM = NUM * 10 + C - '0';
    C = getchar();
  }
  if (TURN) NUM = -NUM;
  return NUM;
}
int n, len, a[300], l1, l2, p, ct, ans;
char s[100005];
int main() {
  n = uf();
  gets(s);
  len = strlen(s);
  ct = 1;
  for (int i = 1; i < len; i++) {
    if (s[i] != s[i - 1]) {
      a[s[i - 1]] = max(a[s[i - 1]], ct);
      ct = 1;
    } else
      ct++;
  }
  a[s[len - 1]] = max(a[s[len - 1]], ct);
  for (int i = 2; i <= n; i++) {
    gets(s);
    len = strlen(s);
    p = 1;
    while (p < len && s[p] == s[p - 1]) p++;
    l1 = p;
    if (l1 == len) {
      a[s[0]] = a[s[0]] + (a[s[0]] + 1) * len;
    }
    if (l1 < len) {
      p = len - 2;
      while (p > 0 && s[p] == s[p + 1]) p--;
      l2 = len - p - 1;
      if (s[0] == s[len - 1]) {
        a[s[0]] = l1 + l2 + 1;
      } else {
        a[s[0]] = 1 + l1;
        a[s[len - 1]] = 1 + l2;
      }
    }
    for (int j = 'a'; j <= 'z'; j++) {
      if (j != s[0] && j != s[len - 1]) a[j] = min(a[j], 1);
    }
    ct = 1;
    for (int j = 1; j < len; j++) {
      if (s[j] != s[j - 1]) {
        a[s[j - 1]] = max(a[s[j - 1]], ct);
        ct = 1;
      } else
        ct++;
    }
    a[s[len - 1]] = max(a[s[len - 1]], ct);
  }
  for (int i = 'a'; i <= 'z'; i++) {
    ans = max(ans, a[i]);
  }
  printf("%d\n", ans);
  return 0;
}
