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;
void getFreq(string str, long long freq[]) {
  for (long long i = 0; i < 26; ++i) freq[i] = 0;
  for (long long i = 0; i < str.length();) {
    char c = str[i];
    long long f = 0;
    while (i < str.length() and str[i] == c) {
      ++f;
      ++i;
    }
    freq[c - 'a'] = max(freq[c - 'a'], f);
  }
}
void merge(long long f[], long long n2[], string str) {
  char cl = str[0];
  char cr = str[str.length() - 1];
  long long l = 0;
  while (l < str.length() and str[l] == cl) ++l;
  long long r = 0;
  while (r < str.length() and str[str.length() - 1 - r] == cr) ++r;
  bool same = (l == str.length() and r == str.length());
  if (same) {
    for (long long i = 0; i < 26; ++i) {
      if (i + 'a' == cl)
        f[i] = max(l * (f[i] + 1) + f[i], f[i]);
      else
        f[i] = max((f[i] > 0 ? 1LL : 0LL), n2[i]);
    }
  } else {
    for (long long i = 0; i < 26; ++i) {
      bool before = (f[i] > 0);
      long long cnt = 0;
      if (before) {
        cnt = 1;
        if (cl == i + 'a') cnt += l;
        if (cr == i + 'a') cnt += r;
      }
      f[i] = cnt;
      f[i] = max(f[i], n2[i]);
    }
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n;
  cin >> n;
  string str;
  long long freq[100];
  long long ans[100];
  cin >> str;
  getFreq(str, ans);
  for (long long i = 1; i < n; ++i) {
    cin >> str;
    getFreq(str, freq);
    merge(ans, freq, str);
  }
  long long maxval = 0;
  for (long long i = 0; i < 26; ++i) maxval = max(maxval, ans[i]);
  cout << maxval << endl;
}
