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;
char arr[100010];
int cnt[256] = {0};
int tc[256] = {0};
void solve() {
  int n;
  scanf("%d", &n);
  scanf("%s", arr);
  int len = strlen(arr);
  char c = 0;
  int cc = 0;
  for (int i = 0; i < len; i++) {
    if (arr[i] == c) {
      cc++;
    } else {
      c = arr[i];
      cc = 1;
    }
    cnt[arr[i]] = max(cnt[arr[i]], cc);
  }
  for (int kkk = 0; kkk < n - 1; kkk++) {
    bool all = true;
    scanf("%s", arr);
    len = strlen(arr);
    c = 0;
    cc = 0;
    for (int i = 0; i < len; i++) {
      all &= arr[i] == arr[0];
      if (arr[i] == c)
        cc++;
      else
        c = arr[i], cc = 1;
      tc[arr[i]] = max(tc[arr[i]], cc);
    }
    if (all) {
      int tmp = 0;
      int ml = cnt[arr[0]];
      if (ml > 0) {
        tc[arr[0]] = (ml + 1) * len + ml;
      }
    } else {
      int cfront = 0, cback = 0;
      for (int i = 0; i < len; i++) {
        if (arr[i] == arr[0])
          cfront++;
        else
          break;
      }
      for (int i = len - 1; i >= 0; i--) {
        if (arr[i] == arr[len - 1])
          cback++;
        else
          break;
      }
      if (arr[0] == arr[len - 1]) {
        if (cnt[arr[0]] > 0) {
          tc[arr[0]] = max(tc[arr[0]], cfront + cback + 1);
        }
      } else {
        if (cnt[arr[0]] > 0) tc[arr[0]] = max(tc[arr[0]], cfront + 1);
        if (cnt[arr[len - 1]] > 0)
          tc[arr[len - 1]] = max(tc[arr[len - 1]], cback + 1);
      }
    }
    for (char c = 'a'; c <= 'z'; c++) {
      if (tc[c] == 0 && cnt[c] > 0)
        cnt[c] = 1;
      else
        cnt[c] = tc[c];
      tc[c] = 0;
    }
  }
  int ans = 0;
  for (char c = 'a'; c <= 'z'; c++) {
    ans = max(ans, cnt[c]);
  }
  printf("%d\n", ans);
}
void init() {}
int main() {
  init();
  solve();
  return 0;
}
