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;
string x[100009];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
  }
  int l = 0, r = 0;
  int ans = 1;
  char L = x[n][0], R = x[n][x[n].length() - 1];
  int co = 1;
  for (int i = 1; i < x[n].length(); i++) {
    if (x[n][i] == x[n][i - 1])
      co++;
    else {
      ans = max(ans, co);
      co = 1;
    }
  }
  ans = max(ans, co);
  int sum = 0;
  if (x[n].length() == 1) {
    sum = 1;
  } else {
    int i;
    for (i = 1; i < x[n].length(); i++) {
      if (x[n][i] != x[n][0]) break;
    }
    i--;
    if (i == x[n].length() - 1) {
      sum = x[n].length();
    } else {
      l = i + 1;
      for (i = x[n].length() - 2;; i--) {
        if (x[n][i] != R) break;
      }
      r = x[n].length() - 1 - i;
    }
  }
  ans = max(ans, max(sum, max(l, r)));
  for (int i = n - 1; i >= 1; i--) {
    if (!l) {
      int f = 0;
      for (int j = 0; j < x[i].length(); j++) {
        if (x[i][j] != L) {
          f = 1;
          l = j + (j + 1) * sum;
          break;
        }
      }
      if (f) {
        for (int j = x[i].length() - 1;; j--) {
          if (x[i][j] != R) {
            r = x[i].length() - 1 - j;
            r = r + (r + 1) * sum;
            break;
          }
        }
        int co = 0;
        for (int j = 0; j < x[i].length(); j++) {
          if (x[i][j] == L)
            co++;
          else {
            ans = max(ans, co + (co + 1) * sum);
            co = 0;
          }
        }
        ans = max(ans, co + (co + 1) * sum);
      } else {
        sum = x[i].length() + (x[i].length() + 1) * sum;
      }
    } else {
      for (int j = 0; j < x[i].length(); j++) {
        if (x[i][j] == L) {
          if (L == R) {
            ans = max(ans, l + r + 1);
          } else {
            ans = max(ans, l + 1);
          }
        } else if (x[i][j] == R) {
          ans = max(ans, r + 1);
        }
      }
    }
  }
  ans = max(ans, max(sum, max(l, r)));
  printf("%d\n", ans);
}
