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 c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f * x;
}
const int maxn = 3e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n;
string p[maxn];
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) cin >> p[i];
  char lchar = p[n][0], rchar = p[n].back();
  int l = 0, r = 0, only = 0;
  for (char c : p[n]) {
    if (c == lchar)
      l++;
    else
      break;
  }
  for (int i = p[n].size() - 1; i >= 0; --i) {
    if (p[n][i] == rchar)
      r++;
    else
      break;
  }
  if (l == p[n].size()) only = 1;
  int cur = 1, mx = 1;
  for (int i = 1; i < p[n].size(); ++i) {
    if (p[n][i] == p[n][i - 1])
      cur++, mx = max(mx, cur);
    else
      cur = 1;
  }
  for (int i = n - 1; i; --i) {
    if (only) {
      int l0 = l, r0 = r;
      for (int j = 0; j < p[i].size(); ++j) {
        if (p[i][j] == lchar)
          l += 1 + l0;
        else
          break;
      }
      for (int j = p[i].size() - 1; j >= 0; --j) {
        if (p[i][j] == rchar)
          r += 1 + r0;
        else
          break;
      }
      mx = max({mx, l, r});
      if (l != l0 + p[i].size() * (1 + l0)) {
        only = 0;
        int cur = 0, ml = 0;
        for (int j = 0; j < p[i].size(); ++j) {
          if (p[i][j] == lchar)
            cur++, ml = max(ml, cur);
          else
            cur = 0;
        }
        mx = max(mx, l0 + ml * (1 + l0));
      }
    } else {
      for (int j = 0; j < p[i].size(); ++j) {
        if (p[i][j] == lchar && lchar == rchar) {
          mx = max(mx, l + r + 1);
        } else if (p[i][j] == lchar) {
          mx = max(mx, l + 1);
        } else if (p[i][j] == rchar) {
          mx = max(mx, r + 1);
        }
      }
    }
  }
  cout << mx << endl;
}
