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;
int n;
long long f[30];
char a[100005];
int la;
long long mx;
long long g[30];
bool check() {
  for (int i = 2; i <= la; ++i)
    if (a[i] != a[i - 1]) return false;
  return true;
}
long long getpre() {
  for (int i = 2; i <= la; ++i)
    if (a[i] != a[i - 1]) return i - 1;
  return la;
}
long long getsuf() {
  for (int i = la - 1; i >= 1; --i)
    if (a[i] != a[i + 1]) return la - (i + 1) + 1;
  return la;
}
int main() {
  scanf("%d", &n);
  scanf("%s", a + 1);
  la = (int)strlen(a + 1);
  for (int i = 1; i <= la; ++i) {
    ++mx;
    f[a[i] - 'a'] = max(f[a[i] - 'a'], mx);
    if (a[i] != a[i + 1]) mx = 0;
  }
  for (int t = 2; t <= n; ++t) {
    scanf("%s", a + 1);
    la = (int)strlen(a + 1);
    if (check()) {
      long long num = f[a[1] - 'a'];
      for (int i = 0; i < 26; ++i)
        if (f[i]) f[i] = 1;
      f[a[1] - 'a'] = num + (num + 1) * la;
    } else {
      mx = 0;
      memset(g, 0, sizeof(g));
      for (int i = 1; i <= la; ++i) {
        ++mx;
        g[a[i] - 'a'] = max(g[a[i] - 'a'], mx);
        if (a[i] != a[i + 1]) mx = 0;
      }
      if (a[1] == a[la]) {
        for (int i = 0; i < 26; ++i)
          if (f[i]) f[i] = 1;
        if (f[a[1] - 'a']) f[a[1] - 'a'] = 1 + getpre() + getsuf();
        for (int i = 0; i < 26; ++i) f[i] = max(f[i], g[i]);
      } else {
        for (int i = 0; i < 26; ++i)
          if (f[i]) f[i] = 1;
        if (f[a[1] - 'a']) f[a[1] - 'a'] = getpre() + 1;
        if (f[a[la] - 'a']) f[a[la] - 'a'] = getsuf() + 1;
        for (int i = 0; i < 26; ++i) f[i] = max(f[i], g[i]);
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < 26; ++i) ans = max(ans, f[i]);
  printf("%lld\n", ans);
  return 0;
}
