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;
char S[100003];
int st[100003];
int len[100003];
int N;
void rin() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%s", S + st[i]);
    len[i] = strlen(S + st[i]);
    st[i + 1] = st[i] + len[i];
  }
}
class poi {
 public:
  int l, r, mx, len;
  bool same;
  char lc, rc;
  poi() {
    l = 0;
    r = 0;
    mx = 0;
    len = 0;
  }
  poi(char c) {
    l = 1;
    r = 1;
    mx = 1;
    len = 1;
    lc = rc = c;
    same = true;
  }
};
inline poi mg(const poi &a, const poi &b) {
  poi ans;
  ans.lc = a.lc;
  ans.rc = b.rc;
  ans.len = a.len + b.len;
  if (a.same)
    ans.l = a.len + (a.rc == b.lc ? b.l : 0);
  else
    ans.l = a.l;
  if (b.same)
    ans.r = (a.rc == b.lc ? a.r : 0) + b.len;
  else
    ans.r = b.r;
  ans.mx = max(a.mx, b.mx);
  if (a.rc == b.lc) {
    ans.mx = max(ans.mx, a.r + b.l);
    ans.same = (a.same & b.same);
  } else
    ans.same = false;
  return ans;
}
poi count(int x, poi last) {
  poi ans;
  ans = last;
  for (int i = 0; i < len[x]; i++) {
    ans = mg(ans, poi(S[st[x] + i]));
    ans = mg(ans, last);
  }
  return ans;
}
void work() {
  poi last;
  last = poi(S[st[N - 1]]);
  for (int i = 1; i < len[N - 1]; i++) last = mg(last, poi(S[st[N - 1] + i]));
  poi u;
  for (int i = N - 2; i >= 0; i--) {
    u = count(i, last);
    last = u;
  }
  printf("%d\n", last.mx);
}
int main() {
  rin();
  work();
  return 0;
}
