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 charac(string &s, array<int, 26> &result) {
  for (int i = 0; i < 26; ++i) result[i] = 0;
  int i = 0, size = s.size();
  while (i < size) {
    int j = i;
    while (s[j] == s[i]) {
      j++;
    }
    result[s[i] - 'a'] = max(result[s[i] - 'a'], j - i);
    i = j;
  }
}
void combine(string &s, array<int, 26> &a, array<int, 26> &b) {
  for (int i = 0; i < 26; ++i) {
    if (b[i] > 0) {
      a[i] = max(a[i], 1);
    }
  }
  pair<char, int> left, right;
  int i = 0, n = s.size();
  while (s[i] == s[0] && i < n) {
    i++;
  }
  left = {s[0], i};
  i = n - 1;
  while (s[i] == s[n - 1] && i >= 0) {
    i--;
  }
  right = {s[n - 1], n - i - 1};
  if (left.first == right.first) {
    if (left.second != n && b[left.first - 'a'] != 0) {
      a[left.first - 'a'] =
          max(a[left.first - 'a'], left.second + right.second + 1);
    } else {
      a[left.first - 'a'] = max(
          a[left.first - 'a'], b[left.first - 'a'] + (b[left.first - 'a'] + 1) *
                                                         a[left.first - 'a']);
    }
  } else {
    if (b[left.first - 'a'] != 0) {
      a[left.first - 'a']++;
    }
    if (b[right.first - 'a']) {
      a[right.first - 'a']++;
    }
  }
}
int main() {
  size_t n;
  cin >> n;
  vector<string> p(n);
  for (int i = 0; i < n; ++i) cin >> p[i];
  array<int, 26> result = {};
  charac(p[0], result);
  for (int i = 1; i < n; ++i) {
    array<int, 26> cur = {};
    charac(p[i], cur);
    combine(p[i], cur, result);
    result = cur;
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) {
    ans = max(ans, result[i]);
  }
  cout << ans;
  return 0;
}
