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 N = 100010;
int n, len, a[26], b[26], lt, p1, p2;
char s[N];
inline void upd(int& x, int y) {
  if (x < y) x = y;
}
void cal() {
  len = strlen(s + 1);
  p1 = 1;
  while (p1 < len && s[1] == s[p1 + 1]) p1++;
  p2 = 1;
  while (p2 < len && s[len] == s[len - p2]) p2++;
  for (int i = 1, cnt = 1; i < len; ++i)
    if (s[i] != s[i + 1]) {
      upd(a[s[i] - 'a'], cnt);
      cnt = 1;
    } else
      cnt++;
  upd(a[s[len] - 'a'], p2);
}
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  cal();
  for (int i = 0; i < 26; ++i) b[i] = a[i], a[i] = 0;
  for (int i = 1; i < n; ++i) {
    scanf("%s", s + 1);
    cal();
    if (p1 == len) {
      int x = s[1] - 'a';
      b[x] = a[x] * b[x] + a[x] + b[x];
      for (int j = 0; j < 26; ++j)
        if (j != x) b[j] = b[j] ? 1 : 0;
    } else if (s[1] == s[len]) {
      int x = s[1] - 'a';
      if (b[x]) b[x] = p1 + p2 + 1;
      for (int j = 0; j < 26; ++j)
        if (j != x) b[j] = b[j] ? 1 : 0;
    } else {
      int x = s[1] - 'a', y = s[len] - 'a';
      if (b[x]) b[x] = p1 + 1;
      if (b[y]) b[y] = p2 + 1;
      for (int j = 0; j < 26; ++j)
        if (j != x && j != y) b[j] = b[j] ? 1 : 0;
    }
    for (int j = 0; j < 26; ++j) upd(b[j], a[j]), a[j] = 0;
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) upd(ans, b[i]);
  cout << ans << endl;
  return 0;
}
