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 N = 100003;
int n;
string p[N];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p[i];
  long long ls = 1, lp = 1, ans = 1;
  char start = p[n - 1][0], finish = p[n - 1][p[n - 1].length() - 1];
  bool single = true;
  long long tmp = 0;
  for (int i = 1; i < p[n - 1].length(); i++) {
    if (p[n - 1][i] == p[n - 1][i - 1])
      tmp++;
    else {
      ans = max(ans, tmp);
      tmp = 0;
      single = false;
    }
  }
  tmp = 0;
  for (int i = 1; i < p[n - 1].length(); i++) {
    if (p[n - 1][i] == p[n - 1][i - 1])
      tmp++;
    else {
      lp = tmp;
      break;
    }
  }
  tmp = 0;
  for (int i = p[n - 1].length() - 2; i >= 0; i++) {
    if (p[n - 1][i] == p[n - 1][i + 1])
      tmp++;
    else {
      ls = tmp;
      break;
    }
  }
  for (int i = n - 2; i >= 0; i--) {
    if (!single) {
      tmp = 0;
      for (int j = 0; j < p[i].length(); j++) {
        if (p[i][j] == start)
          tmp = max(tmp,
                    min(lp + 1 + (start == finish ? ls : 0), (long long)(1e9)));
        if (p[i][j] == finish)
          tmp = max(tmp,
                    min(ls + 1 + (start == finish ? lp : 0), (long long)(1e9)));
        ans = max(ans, tmp);
      }
    } else {
      tmp = 0;
      long long pointer = lp;
      for (int j = 0; j < p[i].length(); j++) {
        if (p[i][j] == start) {
          pointer += (lp + 1);
          lp = min(lp, (long long)1e9);
        } else {
          tmp = max(tmp, pointer);
          pointer = lp;
        }
      }
      ans = max(ans, tmp);
      long long _ls = ls, _lp = lp;
      for (int j = 0; j < p[i].length(); j++) {
        if (p[i][j] == start) {
          _lp += (lp + 1);
          _lp = min(_lp, (long long)(1e9));
        } else {
          single = false;
          break;
        }
      }
      for (int j = p[i].length() - 2; j >= 0; j--) {
        if (p[i][j] == finish) {
          _ls += (ls + 1);
          _ls = min(_ls, (long long)(1e9));
        } else {
          single = false;
          break;
        }
      }
      ls = _ls;
      lp = _lp;
    }
  }
  cout << ans;
}
