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>
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
  return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }
long long flipBit(int num, int idx) { return num ^ (1 << idx); }
void FS() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int countNumBit1(int mask) {
  int ret = 0;
  while (mask) {
    mask &= (mask - 1);
    ++ret;
  }
  return ret;
}
const int N = 100009;
string s[N];
int n, vis[27];
int longest(string &s, char c) {
  int mx = 0, cnt = 0;
  for (int i = 0; i < ((int)(s).size()); i++) {
    if (s[i] == c)
      cnt++;
    else
      mx = max(mx, cnt), cnt = 0;
  }
  mx = max(mx, cnt);
  return mx;
}
int getP(string &s, char c) {
  int cnt = 0;
  for (int i = 0; i < ((int)(s).size()); i++) {
    if (s[i] == c)
      cnt++;
    else
      break;
  }
  return cnt;
}
int getS(string &s, char c) {
  int cnt = 0;
  for (int i = ((int)(s).size()) - 1; i >= 0; i--) {
    if (s[i] == c)
      cnt++;
    else
      break;
  }
  return cnt;
}
int solve(int n, char c) {
  int res = longest(s[1], c);
  for (int i = 2; i <= n; i++) {
    int lgs = longest(s[i], c);
    int prefix = longest(s[i], c);
    int suffix = longest(s[i], c);
    if (lgs == ((int)(s[i]).size())) {
      res = res + lgs * (res + 1);
    } else if (res > 0) {
      res = max(prefix + suffix + 1, lgs);
    } else {
      res = lgs;
    }
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    for (int j = 0; j < ((int)(s[i]).size()); j++) {
      vis[s[i][j] - 'a']++;
    }
  }
  int ans = 1;
  for (int i = 0; i < 26; i++)
    if (vis[i] > 0) ans = max(ans, solve(n, i + 'a'));
  cout << ans << endl;
}
