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 = 1e5 + 5;
int n, m;
long long a[26], b[26];
char s[N];
int len, p1, p2;
void cal() {
  memset(a, 0, sizeof(a));
  len = strlen(s);
  p1 = p2 = 1;
  int pos = 1;
  while (pos < len && s[pos] == s[pos - 1]) p1++, pos++;
  pos = len - 2;
  while (pos >= 0 && s[pos] == s[pos + 1]) p2++, pos--;
  int cn = 0;
  for (int i = 1; i < len; i++) {
    if (s[i] != s[i - 1]) {
      a[s[i - 1] - 'a'] = max(a[s[i - 1] - 'a'], 1ll * cn);
    } else
      cn++;
  }
  a[s[len - 1] - 'a'] = max(a[s[len - 1] - 'a'], 1ll * cn);
}
void view() {
  for (int i = 0; i < 26; i++) {
    cout << b[i] << " ";
  }
  cout << endl;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    cal();
    if (p1 + p2 > len) {
      b[s[0] - 'a'] = b[s[0] - 'a'] * (len + 1) + len;
      if (b[s[0] - 'a'] > 1e9) b[s[0] - 'a'] = 1e9;
      for (int j = 0; j < 26; j++) {
        if (j == s[0] - 'a') continue;
        b[j] = b[j] ? 1 : 0;
        b[j] = max(b[j], a[j]);
      }
    } else if (s[0] == s[len - 1]) {
      if (b[s[0] - 'a'])
        b[s[0] - 'a'] = p1 + p2 + 1;
      else
        b[s[0] - 'a'] = max(p1, p2);
      for (int j = 0; j < 26; j++) {
        if (j == s[0] - 'a') continue;
        b[j] = b[j] ? 1 : 0;
        b[j] = max(b[j], a[j]);
      }
    } else {
      b[s[0] - 'a'] = (b[s[0] - 'a'] ? 1 : 0) + p1;
      b[s[len - 1] - 'a'] = (b[s[len - 1] - 'a'] ? 1 : 0) + p2;
      for (int j = 0; j < 26; j++) {
        if (j == s[0] - 'a' || j == s[len - 1] - 'a') continue;
        b[j] = b[j] ? 1 : 0;
        b[j] = max(b[j], a[j]);
      }
    }
  }
  long long ans = b[0];
  for (int i = 1; i < 26; i++) {
    ans = max(ans, b[i]);
  }
  cout << ans << endl;
}
