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 = (int)1e6 + 10;
const int MOD = (int)1e9 + 7;
struct Result {
  int prefix;
  int suffix;
  int ans;
  bool isFull;
  Result() {
    prefix = suffix = ans = 0;
    isFull = false;
  }
};
string p[N];
Result combine(Result a, Result b) {
  Result res;
  if (a.isFull && b.isFull) {
    res.prefix = a.prefix + b.prefix;
    res.suffix = res.ans = res.prefix;
    res.isFull = true;
    return res;
  }
  res.isFull = false;
  res.prefix = a.prefix;
  if (a.isFull) res.prefix += b.prefix;
  res.suffix = b.suffix;
  if (b.isFull) res.suffix += a.suffix;
  res.ans = max(a.ans, b.ans);
  res.ans = max(res.ans, a.suffix + b.prefix);
  return res;
}
Result solve(char ch, int n) {
  Result now;
  if (n == 1) {
    for (int i = 0; i < p[n].size(); i++) {
      if (p[n][i] == ch)
        now.prefix++;
      else
        break;
    }
    for (int i = (int)p[n].size() - 1; i >= 0; i--) {
      if (p[n][i] == ch)
        now.suffix++;
      else
        break;
    }
    now.isFull = (now.prefix == (int)p[n].size());
    int cnt = 0;
    for (int i = 0; i < p[n].size(); i++) {
      if (p[n][i] == ch) {
        ++cnt;
        now.ans = max(now.ans, cnt);
      } else {
        cnt = 0;
      }
    }
    return now;
  }
  Result block;
  block = solve(ch, n - 1);
  now = block;
  for (auto it : p[n]) {
    if (it == ch) {
      now.suffix++;
      now.ans = max(now.ans, now.suffix);
      if (now.isFull) now.prefix++;
    } else {
      now.suffix = 0;
      now.isFull = 0;
    }
    now = combine(now, block);
  }
  return now;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
  }
  reverse(p + 1, p + n + 1);
  int ans = 0;
  for (char c = 'a'; c <= 'z'; c++) {
    Result cur = solve(c, n);
    ans = max(ans, cur.ans);
  }
  cout << ans;
  return 0;
}
