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>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 1e18;
inline int readint() {
  int x = 0, s = 1, c = getchar();
  while (c <= 32) c = getchar();
  if (c == '-') s = -1, c = getchar();
  for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
  return x * s;
}
const int maxn = 1e5 + 5;
vector<long long> getLength(string s) {
  vector<long long> v(26, 0);
  int len = 1, last = -1;
  for (int i = 0; i <= s.length() - 1; i++) {
    int now = s[i] - 'a';
    if (now == last) {
      len++;
    } else {
      last = now;
      len = 1;
    }
    v[now] = max(v[now], (long long)len);
  }
  return v;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> Len = getLength(s);
  for (int i = 1; i <= n - 1; i++) {
    cin >> s;
    int prec = s[0] - 'a', sufc = s.back() - 'a';
    int prel = 1, sufl = 1;
    for (int j = 1; j <= s.length() - 1; j++) {
      if (s[j] - 'a' == prec)
        prel++;
      else
        break;
    }
    for (int j = s.length() - 2; j >= 0; j--) {
      if (s[j] - 'a' == sufc)
        sufl++;
      else
        break;
    }
    vector<long long> cur = getLength(s);
    if (prel == s.length()) {
      for (int j = 0; j <= 25; j++) {
        if (j == prec) {
          Len[j] += (Len[j] + 1) * prel;
        } else {
          Len[j] = min(Len[j], 1ll);
        }
      }
    } else {
      for (int j = 0; j <= 25; j++) {
        Len[j] = (prec == j) * prel + (sufc == j) * sufl + 1;
        Len[j] = max(Len[j], cur[j]);
      }
    }
    for (int j = 0; j <= 25; j++) Len[j] = min(Len[j], (long long)1e9);
  }
  long long ans = -1;
  for (int i = 0; i <= 25; i++) ans = max(ans, Len[i]);
  cout << ans << endl;
  return 0;
}
