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;
const int maxn = 1e5 + 50;
char str[maxn];
int pre[30], now[30];
int l, r, len, cnt;
void sov() {
  scanf("%s", str);
  len = strlen(str);
  cnt = 1;
  l = 0, r = 0;
  memset(now, 0, sizeof(now));
  int i = 1;
  while (i < len) {
    if (str[i] == str[i - 1])
      cnt++;
    else
      break;
    i++;
  }
  if (cnt == len) return;
  l = cnt;
  cnt = 1;
  int j = len - 2;
  while (j >= 0) {
    if (str[j] == str[j + 1])
      cnt++;
    else
      break;
    j--;
  }
  r = cnt;
  if (r + l == len) return;
  cnt = 1;
  for (++i; i <= j + 1; i++) {
    if (str[i] != str[i - 1]) {
      now[str[i - 1] - 'a'] = max(now[str[i - 1] - 'a'], cnt);
      cnt = 1;
    } else if (str[i] == str[i - 1])
      cnt++;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int j = 0; j < n; j++) {
    sov();
    if (cnt == len) {
      int t = str[0] - 'a';
      pre[t] = pre[t] + (pre[t] + 1) * len;
      for (int i = 0; i < 26; i++)
        if (i != t) {
          if (pre[i])
            pre[i] = 1;
          else
            pre[i] = 0;
        }
    } else if (str[0] == str[len - 1]) {
      int t = str[0] - 'a';
      if (pre[t])
        pre[t] = max(now[t], l + r + 1);
      else
        pre[t] = max(max(l, r), now[t]);
      for (int i = 0; i < 26; i++)
        if (i != t) {
          if (pre[i])
            pre[i] = max(1, now[i]);
          else
            pre[i] = now[i];
        }
    } else {
      int t = str[0] - 'a';
      if (pre[t])
        pre[t] = max(1 + l, now[t]);
      else
        pre[t] = max(l, now[t]);
      t = str[len - 1] - 'a';
      if (pre[t])
        pre[t] = max(1 + r, now[t]);
      else
        pre[t] = max(r, now[t]);
      for (int i = 0; i < 26; i++)
        if (i != str[0] - 'a' && i != str[len - 1] - 'a') {
          if (pre[i])
            pre[i] = max(1, now[i]);
          else
            pre[i] = now[i];
        }
    }
  }
  int ans = -1;
  for (int i = 0; i < 26; i++) ans = max(ans, pre[i]);
  printf("%d\n", ans);
  return 0;
}
