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 void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = v * 10 + c - '0';
  while (isdigit(c = getchar())) v = v * 10 + c - '0';
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while ((c = getchar()) == ' ')
    ;
  x = c;
}
inline void writes(string s) { puts(s.c_str()); }
inline void writeln() { writes(""); }
inline void writei(int x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
inline void writell(long long x) {
  if (x < 0) {
    putchar('-');
    x = abs(x);
  }
  if (!x) putchar('0');
  char a[25];
  int top = 0;
  while (x) {
    a[++top] = (x % 10) + '0';
    x /= 10;
  }
  while (top) {
    putchar(a[top]);
    top--;
  }
}
int n, m, i, j, mx = 1;
string st[100005];
char ss[100005];
struct nd {
  int sl, sr, sc, sum;
  char cl, cr;
} f, g, h;
nd add(nd x, nd y) {
  nd ans;
  ans.sum = min(x.sum + y.sum, 1000000000);
  ans.cl = x.cl;
  ans.cr = y.cr;
  if (x.sl == x.sum && x.cl == y.cl)
    ans.sl = x.sum + y.sl;
  else
    ans.sl = x.sl;
  if (y.sr == y.sum && x.cr == y.cr)
    ans.sr = y.sum + x.sr;
  else
    ans.sr = y.sr;
  ans.sc = max(x.sc, y.sc);
  if (x.cr == y.cl) ans.sc = max(ans.sc, x.sr + y.sl);
  ans.sl = min(ans.sl, 1000000000);
  ans.sr = min(ans.sr, 1000000000);
  ans.sc = min(ans.sc, 1000000000);
  mx = max(mx, ans.sc);
  return ans;
}
int main() {
  scanf("%d", &n);
  if ((1) <= ((n)))
    for (((i)) = (1); ((i)) <= ((n)); ((i))++) {
      scanf(" %s", ss);
      st[i] = ss;
    }
  for (i = 0; i < st[n].size(); i++)
    if (st[n][i] != st[n][0]) break;
  f.sl = i;
  int len = st[n].size() - 1;
  for (i = len; i >= 0; i--) {
    if (st[n][i] != st[n][len]) break;
  }
  f.sr = len - i;
  int sss = 0;
  for (i = 0; i < st[n].size(); i++) {
    if (i && st[n][i] != st[n][i - 1]) {
      sss = 1;
    } else {
      sss++;
    }
    f.sc = max(f.sc, sss);
  }
  f.sum = st[n].size();
  f.cl = st[n][0];
  f.cr = st[n][len];
  mx = max(mx, f.sc);
  if (((n - 1)) >= (1))
    for (((i)) = ((n - 1)); ((i)) >= (1); ((i))--) {
      h = f;
      for (j = 0; j < st[i].size(); j++) {
        g = (nd){1, 1, 1, 1, st[i][j], st[i][j]};
        h = add(add(h, g), f);
      }
    }
  cout << mx << endl;
  return 0;
}
