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;
string s[100010];
int n, len[101000], pre[101000], nt[101000], anp, ann, ansmax, flag;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) cin >> s[n - i + 1];
  for (int i = 1; i <= n; i++) {
    int sum = 1;
    len[i] = s[i].size();
    for (int j = 1; j < len[i]; j++) {
      if (s[i][j] == s[i][0])
        sum++;
      else
        break;
    }
    pre[i] = sum;
    sum = 1;
    for (int j = len[i] - 2; j >= 0; j--) {
      if (s[i][j] == s[i][len[i] - 1])
        sum++;
      else
        break;
    }
    nt[i] = sum;
  }
  anp = pre[1];
  ann = nt[1];
  if (len[1] == pre[1]) {
    flag = 1;
    ansmax = len[1];
  } else {
    flag = 0;
    ansmax = max(pre[1], nt[1]);
  }
}
void do1(int i) {
  if (s[i][0] == s[1][0]) {
    ann = anp = anp + ann + len[i];
    ansmax = max(ansmax, anp);
  } else
    flag = 0;
}
void do4(int i) {
  int sum = len[i];
  if (s[i][0] == s[1][len[1] - 1]) sum += ann;
  if (s[i][0] == s[1][0]) sum += anp;
  ansmax = max(ansmax, sum);
}
void do3(int i) {
  if (s[i][0] == s[1][len[1] - 1]) ansmax = max(ansmax, pre[i] + ann);
  if (s[i][len[i] - 1] == s[1][0]) ansmax = max(ansmax, nt[i] + anp);
}
void do2(int i) {
  if (s[i][0] == s[1][0]) {
    anp = anp + pre[i];
    ansmax = max(ansmax, anp);
  }
  if (s[i][len[i] - 1] == s[1][0]) {
    ann = ann + nt[i];
    ansmax = max(ansmax, ann);
  }
  flag = 0;
}
void work() {
  for (int i = 2; i <= n; i++) {
    if (flag == 1 && len[i] == pre[i])
      do1(i);
    else if (flag == 1 && len[i] != pre[i])
      do2(i);
    else if (flag != 1 && len[i] != pre[i])
      do3(i);
    else if (flag != 1 && len[i] == pre[i])
      do4(i);
    if (n == 3000 && ansmax > 4) cout << s[i] << " " << s[1];
  }
}
int main() {
  init();
  work();
  printf("%d\n", ansmax);
}
