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 mod = 1e9 + 7;
const int maxn = 1e5 + 5;
vector<char> s[maxn];
int fmaxsub(int i, char c) {
  int re = 0;
  int x = 0;
  for (int j = 0; j < s[i].size(); j++) {
    if (s[i][j] == c)
      x++;
    else {
      re = max(x, re);
      x = 0;
    }
  }
  return max(re, x);
}
int fl(int i, char c) {
  int re = -1;
  while (re + 1 < (int)s[i].size() && s[i][re + 1] == c) re++;
  return re + 1;
}
int fr(int i, char c) {
  int re = s[i].size();
  while (re - 1 >= 0 && s[i][re - 1] == c) re--;
  return s[i].size() - re;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    char ts[maxn];
    cin >> ts;
    int le = strlen(ts);
    for (int j = 0; j < le; j++) {
      s[i].push_back(ts[j]);
    }
  }
  int ans = 0;
  char lc = s[n][0], rc = s[n][s[n].size() - 1];
  int l = fl(n, lc), r = fr(n, rc);
  bool same = 1;
  ans = max(l, r);
  if (l != s[n].size()) same = 0;
  for (int i = n - 1; i >= 1; i--) {
    if (same == 1) {
      int fms = fmaxsub(i, rc);
      ans = max(ans, l * (fms) + l);
      int countl = fl(i, lc);
      l = (l) * (countl) + l;
      int countr = fr(i, rc);
      r = (r) * (countr) + r;
      if (fms < s[i].size()) same = 0;
    } else {
      for (int j = 0; j < (int)s[i].size(); j++) {
        int a = 0;
        int b = 0;
        if (rc == s[i][j]) {
          a = r;
        }
        if (lc == s[i][j]) {
          b = l;
        }
        ans = max(ans, a + b + 1);
      }
    }
  }
  cout << max(ans, max(l, r));
  return 0;
}
