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;
inline int read() {
  int x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return x * f;
}
const int N = 100010, AS = 26;
int tans;
struct Data {
  int lc, lnum, rc, rnum, len;
  Data() { lc = lnum = rc = rnum = len = 0; }
};
inline Data operator+(const Data& t1, const char& t2) {
  Data ans = t1;
  char c = t2 - 'a';
  if (c == ans.rc) {
    ++ans.rnum;
  } else {
    ans.rc = c, ans.rnum = 1;
  }
  if (ans.lnum == ans.len && ans.lc == c) ++ans.lnum;
  if (!ans.len) ans.lc = c, ans.lnum = 1;
  ++ans.len;
  tans = max(tans, ans.rnum);
  return ans;
}
inline Data operator+(const Data& t1, const Data& t2) {
  Data ans;
  ans.lc = t1.lc, ans.rc = t2.rc, ans.len = t1.len + t2.len;
  ans.lnum = t1.lnum, ans.rnum = t2.rnum;
  if (t1.rc == t2.lc) {
    tans = max(tans, t1.rnum + t2.lnum);
    if (t1.lnum == t1.len) ans.lnum += t2.lnum;
    if (t2.rnum == t2.len) ans.rnum += t1.rnum;
  }
  return ans;
}
string s[N];
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> s[i];
  Data now, pre;
  int tl = s[n].size();
  for (int j = 0; j < tl; ++j) now = now + s[n][j];
  pre = now;
  for (int i = n - 1; i; --i) {
    int len = s[i].size();
    for (int j = 0; j < len; ++j) now = now + s[i][j] + pre;
    pre = now;
  }
  cout << tans << endl;
  return 0;
}
