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;
long long a[26];
int extraA[26];
void update_num(string p) {
  char c = p[0];
  extraA[p[0] - 'a'] = 1;
  long long num = 1;
  a[c - 'a'] = max(a[c - 'a'], num);
  for (int i = 1; i < p.size(); i++) {
    extraA[p[i] - 'a'] = 1;
    if (c == p[i]) {
      num++;
    } else {
      a[c - 'a'] = max(a[c - 'a'], num);
      num = 1;
    }
    c = p[i];
  }
  a[c - 'a'] = max(a[c - 'a'], num);
}
int main() {
  int n;
  cin >> n;
  string p;
  cin >> p;
  update_num(p);
  for (int i = 1; i < n; i++) {
    cin >> p;
    char h = p[0], t = p[p.size() - 1];
    long long hn = 0, tn = 0;
    for (int i = 0; i < p.size(); i++) {
      if (h != p[i]) {
        break;
      }
      hn++;
    }
    for (int i = p.size() - 1; i >= 0; i--) {
      if (t != p[i]) {
        break;
      }
      tn++;
    }
    if (hn == p.size()) {
      a[h - 'a'] = (a[h - 'a'] + 1) * hn + a[h - 'a'];
      for (int i = 0; i < 26; i++) {
        if (i == h - 'a') {
          continue;
        }
        if (a[i] > 0) {
          a[i] = 1;
        }
      }
    } else if (h == t) {
      a[h - 'a'] = min(extraA[h - 'a'], 1) + hn + tn;
      for (int i = 0; i < 26; i++) {
        if (i == h - 'a') {
          continue;
        }
        if (a[i] > 0) {
          a[i] = 1;
        }
      }
    } else {
      a[h - 'a'] = min(1, extraA[h - 'a']) + hn;
      a[t - 'a'] = min(1, extraA[t - 'a']) + tn;
      for (int i = 0; i < 26; i++) {
        if (i == h - 'a' || i == t - 'a') {
          continue;
        }
        if (a[i] > 0) {
          a[i] = 1;
        }
      }
    }
    update_num(p);
  }
  long long ans = 0;
  for (int i = 0; i < 26; i++) {
    ans = max(ans, a[i]);
  }
  cout << ans << endl;
  return 0;
}
