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;
int w[26];
pair<int, char> pref, suf;
string s;
int n, cnt, pos, ans = 1;
void count_pref_and_suf() {
  pos = 1;
  cnt = 1;
  pref = {1, s[0]};
  suf = {1, s[n - 1]};
  for (int i = 1; i < n; i++) {
    if (s[i] == s[i - 1]) {
      cnt++;
      if (pos) {
        pref.first = cnt;
      }
    } else {
      cnt = 1;
      pos = 0;
    }
  }
  suf.first = cnt;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int q;
  cin >> q;
  cin >> s;
  cnt = 1;
  w[s[0] - 'a']++;
  for (int i = 1; i < s.length(); i++) {
    if (s[i] == s[i - 1]) {
      cnt++;
    } else {
      cnt = 1;
    }
    w[s[i] - 'a'] = max(cnt, w[s[i] - 'a']);
  }
  for (int i = 1; i < q; i++) {
    cin >> s;
    n = s.length();
    count_pref_and_suf();
    if (pref.first == n) {
      for (int i = 0; i < 26; i++) {
        if (w[i]) {
          if (i == pref.second - 'a') {
            w[pref.second - 'a'] =
                n * (w[pref.second - 'a'] + 1) + w[pref.second - 'a'];
          } else
            w[i] = 1;
        }
      }
    } else {
      for (int i = 0; i < 26; i++) {
        if (w[i]) {
          w[i] = 1;
          if (i == pref.second - 'a') w[i] += pref.first;
          if (i == suf.second - 'a') w[i] += suf.first;
        }
      }
    }
    cnt = 1;
    w[s[0] - 'a'] = max(w[s[0] - 'a'], 1);
    for (int i = 1; i < n; i++) {
      if (s[i] == s[i - 1]) {
        cnt++;
      } else {
        cnt = 1;
      }
      w[s[i] - 'a'] = max(w[s[i] - 'a'], cnt);
    }
  }
  for (int i = 0; i < 26; i++) {
    ans = max(ans, w[i]);
  }
  cout << ans << "\n";
  return 0;
}
