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 int Read() {
  int ret = 0, flag = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    ret = ret * 10 + (ch - '0');
    ch = getchar();
  }
  return ret * flag;
}
const int maxn = 1e5 + 7;
const long long Range = 1e9 + 1;
char Str[maxn];
long long ans[50];
void Show() {
  printf(
      "\n-----------------------------------Start------------------------------"
      "-----\n");
  for (int i = 0; i <= 5; i++) {
    printf("%c : %I64d\n", 'a' + i, ans[i]);
  }
  printf(
      "-----------------------------------End----------------------------------"
      "-\n\n");
}
int main() {
  int n = Read(), tmp = 0, ch, len;
  scanf("%s", Str + 1);
  Str[0] = '7';
  for (int i = 1; Str[i] != '\0'; i++) {
    if (Str[i] != Str[i - 1]) tmp = 0;
    tmp++;
    ch = Str[i] - 'a';
    ans[ch] = max(ans[ch], 1LL * tmp);
  }
  for (int i = 2; i <= n; i++) {
    scanf("%s", Str + 1);
    for (len = 1; Str[len] != '\0'; len++) {
      if (Str[len] != Str[len - 1]) tmp = 0;
      tmp++;
    }
    if (tmp == len - 1) {
      ch = Str[1] - 'a';
      ans[ch] = 1LL * (ans[ch] + 1) * tmp + ans[ch];
      for (int j = 0; j <= 25; j++)
        if (j != ch && ans[j] > 0) ans[j] = 1LL;
    } else {
      int st = 1, ed = len - 1;
      int c1 = Str[1] - 'a', c2 = Str[len - 1] - 'a';
      while (Str[st] == Str[1]) st++;
      while (Str[ed] == Str[len - 1]) ed--;
      for (int j = 0; j <= 25; j++) {
        if (ans[j] == 0) continue;
        ans[j] = 1LL;
        if (c1 == j) ans[j] += st - 1;
        if (c2 == j) ans[j] += len - ed - 1;
      }
      for (int j = st; j <= ed; j++) {
        if (Str[j] != Str[j - 1]) tmp = 0;
        tmp++;
        ch = Str[j] - 'a';
        ans[ch] = max(ans[ch], 1LL * tmp);
      }
    }
    for (int j = 0; j <= 30; j++)
      if (ans[j] >= Range) ans[j] = 1LL;
  }
  long long Ans = 0;
  for (int i = 0; i <= 30; i++) Ans = max(Ans, ans[i]);
  cout << Ans << endl;
  return 0;
}
