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 maxn = 100010;
bool onlyone;
char prec, sufc, chc;
int pren, sufn, num[27], dp[27], leij;
int n;
string s1[maxn];
int main() {
  memset(dp, 0, sizeof(dp));
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1[i];
  }
  for (int i = 0; i < n; i++) {
    onlyone = 0;
    prec = s1[i][0];
    sufc = s1[i][s1[i].size() - 1];
    for (int j = 1; j < s1[i].size(); j++) {
      if (s1[i][j] != s1[i][j - 1]) {
        pren = j;
        break;
      }
      if (j == s1[i].size() - 1) pren = s1[i].size(), onlyone = 1;
    }
    if (s1[i].size() == 1) onlyone = 1, pren = 1;
    for (int j = s1[i].size() - 2; j >= 0; j--) {
      if (s1[i][j] != s1[i][j + 1]) {
        sufn = j;
        break;
      }
    }
    memset(num, 0, sizeof(num));
    chc = prec, leij = 1;
    for (int j = 1; j < s1[i].size(); j++) {
      if (s1[i][j] != s1[i][j - 1]) {
        num[chc - 'a'] = max(num[chc - 'a'], leij);
        leij = 0;
      }
      leij++;
    }
    num[chc - 'a'] = max(num[chc - 'a'], leij);
    if (onlyone == 1) {
      for (int j = 0; j < 26; j++) {
        if (dp[j] != 0 && j != prec - 'a') {
          dp[j] = 1;
        }
      }
      dp[prec - 'a'] = (dp[prec - 'a'] + 1) * (pren + 1) - 1;
    } else {
      dp[prec - 'a'] = (dp[prec - 'a'] > 0) + pren;
      if (prec == sufc) {
        dp[sufc - 'a'] += sufn;
      } else
        dp[sufc - 'a'] = (dp[sufc - 'a'] > 0) + sufn;
      cout << i << " " << sufc - 'a' << " " << dp[sufc - 'a'] << endl;
      for (int j = 0; j < 26; j++) {
        if (j != sufc - 'a' && j != prec - 'a')
          dp[j] = max((int)(dp[j] > 1), num[j]);
        else
          dp[j] = max(dp[j], num[j]);
      }
    }
  }
  int res = 0;
  for (int i = 0; i < 26; i++) res = max(res, dp[i]);
  cout << res << endl;
  return 0;
}
