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;
vector<long long> bs(26);
void build_bs(string s) {
  for (long long i = 0; i < 26; ++i) {
    long long ans = 0;
    for (long long j = 0; j < s.size(); ++j) {
      long long cnt = 0;
      while (s[j] - 'a' == i && j < s.size()) {
        ++cnt;
        ++j;
      }
      ans = max(ans, cnt);
    }
    bs[i] = ans;
  }
}
void update_bs(string s) {
  bool check = true;
  for (long long i = 1; i < s.size(); ++i) {
    if (s[i] != s[i - 1]) {
      check = false;
      break;
    }
  }
  if (check) {
    bs[s[0] - 'a'] = s.size() * (bs[s[0] - 'a'] + 1) + bs[s[0] - 'a'];
    for (long long i = 0; i < 26; ++i) {
      if (i != s[0] - 'a' && bs[i] > 0) bs[i] = 1;
    }
    return;
  }
  for (long long i = 0; i < 26; ++i) {
    long long ans = 0;
    for (long long j = 0; j < s.size(); ++j) {
      long long cnt = 0;
      while (s[j] - 'a' == i && j < s.size()) {
        ++cnt;
        ++j;
      }
      ans = max(ans, cnt);
    }
    if (bs[i] > 0) bs[i] = 1;
    bs[i] = max(bs[i], ans);
  }
  long long cnt = 0;
  while (s[cnt] == s[0]) ++cnt;
  long long cnt2 = 0;
  while (s[s.size() - 1 - cnt2] == s[0]) ++cnt2;
  if (bs[s[0] - 'a'] > 0) bs[s[0]] = 1 + cnt + cnt2;
  cnt = 0;
  while (s[cnt] == s[s.size() - 1]) ++cnt;
  cnt2 = 0;
  while (s[s.size() - 1 - cnt2] == s[s.size() - 1]) ++cnt2;
  if (bs[s[s.size() - 1] - 'a'] > 0) bs[s[s.size() - 1] - 'a'] = 1 + cnt + cnt2;
}
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  build_bs(s);
  for (long long i = 1; i < n; ++i) {
    cin >> s;
    update_bs(s);
  }
  long long ans = 0;
  for (long long i = 0; i < 26; ++i) ans = max(ans, bs[i]);
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
