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 = 100005;
int n, len[N];
char str[N];
vector<char> s[N];
inline void read(int &i) {
  i = 0;
  char c = getchar();
  bool j = 0;
  for (; !isdigit(c); c = getchar())
    if (c == '-') j = 1;
  for (; isdigit(c); c = getchar()) i = (i << 1) + (i << 3) + c - '0';
  i = j ? -i : i;
}
struct dat {
  int a, l, r, L, R;
  bool t;
} t, ans;
inline dat operator+(dat a, dat b) {
  if (!a.a) return b;
  if (!b.a) return a;
  dat c;
  bool f = (a.r == b.l);
  c.a = max(max(a.a, b.a), f ? a.R + b.L : 0);
  c.l = a.l;
  c.r = b.r;
  c.L = a.L + (a.t && f ? b.L : 0);
  c.R = b.R + (b.t && f ? a.R : 0);
  c.t = a.t & b.t & f;
  return c;
}
inline dat gen(char x) {
  dat a;
  a.a = a.L = a.R = a.t = 1;
  a.l = a.r = x - 'a';
  return a;
}
int main() {
  read(n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", str + 1);
    len[i] = strlen(str + 1);
    s[i].resize(len[i] + 5);
    for (int j = 1; j <= len[i]; ++j) s[i][j] = str[j];
  }
  for (int i = n; i >= 1; --i) {
    ans = t;
    for (int j = 1; j <= len[i]; ++j) ans = ans + gen(s[i][j]), ans = ans + t;
    t = ans;
  }
  printf("%d\n", ans.a);
  return 0;
}
