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>
const int MAXN = 3e5 + 10;
const double eps = 1e-8;
using namespace std;
struct edge {
  int t, v;
  edge *next;
} e[MAXN << 1], *h[MAXN], *o = e;
void add(int x, int y, int vul) {
  o->t = y;
  o->v = vul;
  o->next = h[x];
  h[x] = o++;
}
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
long long num[26], num1[26];
char str[MAXN];
int main() {
  int n = read();
  scanf("%s", str + 1);
  int len = strlen(str + 1);
  long long cnt = 1;
  for (int i = 2; i <= len; i++) {
    if (str[i] != str[i - 1])
      num[str[i - 1] - 'a'] = max(num[str[i - 1] - 'a'], cnt), cnt = 1;
    else
      cnt++;
  }
  num[str[len] - 'a'] = max(num[str[len] - 'a'], cnt);
  n--;
  while (n--) {
    scanf("%s", str + 1);
    len = strlen(str + 1);
    for (int i = 0; i <= 25; i++) num1[i] = 0;
    int l = 1, r = 1;
    for (int i = 2; i <= len; i++)
      if (str[i] == str[i - 1])
        l++;
      else
        break;
    for (int i = len - 1; i >= 1; i--)
      if (str[i] == str[i + 1])
        r++;
      else
        break;
    if (l == r && l == len) {
      int t = str[1] - 'a';
      if (num[t])
        num[t] = 1ll * (num[t] + 1) * l + num[t];
      else
        num[t] = l;
      for (int i = 0; i <= 25; i++) {
        if (i == t) continue;
        if (num[i]) num[i] = 1;
      }
    } else {
      cnt = 1;
      for (int i = 2; i <= len; i++) {
        if (str[i] != str[i - 1])
          num1[str[i - 1] - 'a'] = max(num1[str[i - 1] - 'a'], cnt), cnt = 1;
        else
          cnt++;
      }
      num1[str[len] - 'a'] = max(num1[str[len] - 'a'], cnt);
      int t1 = str[1] - 'a';
      int t2 = str[len] - 'a';
      for (int i = 0; i <= 25; i++) {
        if (!num[i]) continue;
        num[i] = 1;
        if (i == t1) num[i] += l;
        if (i == t2) num[i] += r;
      }
      for (int i = 0; i <= 25; i++) num[i] = max(num[i], num1[i]);
    }
  }
  long long maxx = 0;
  for (int i = 0; i <= 25; i++) maxx = max(maxx, num[i]);
  printf("%lld\n", maxx);
}
