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 n;
long long len[26], tlen[26];
pair<int, int> pre, suf;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> s;
  int cur = 1;
  len[s[0] - 'a'] = 1;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1])
      cur++;
    else {
      len[s[i - 1] - 'a'] = max(len[s[i - 1] - 'a'], (long long)cur);
      cur = 1;
    }
    if (i == s.size() - 1)
      len[s[i] - 'a'] = max(len[s[i] - 'a'], (long long)cur);
  }
  bool ok;
  for (int z = 2; z <= n; z++) {
    cin >> s;
    ok = 1;
    for (int i = 1; i < s.size(); i++) {
      if (s[i] != s[i - 1]) {
        ok = 0;
        break;
      }
    }
    if (ok == 1) {
      for (int i = 0; i < 26; i++) {
        if (s[0] - 'a' == i)
          len[i] = len[i] + (long long)(s.size()) * (len[i] + 1);
        else
          len[i] = min((long long)1, max((long long)0, len[i]));
      }
    } else {
      int j = 1;
      pre = {s[0] - 'a', 1};
      while (j < s.size() && s[j] == s[0]) {
        pre.second++;
        j++;
      }
      j = (int)(s.size()) - 2;
      suf = {s[s.size() - 1] - 'a', 1};
      while (j >= 0 && s[j] == s[s.size() - 1]) {
        suf.second++;
        j--;
      }
      for (int i = 0; i < 26; i++) tlen[i] = 0;
      cur = 1;
      tlen[s[0] - 'a'] = 1;
      for (int i = 1; i < s.size(); i++) {
        if (s[i] == s[i - 1])
          cur++;
        else {
          tlen[s[i - 1] - 'a'] = max(tlen[s[i - 1] - 'a'], (long long)cur);
          cur = 1;
        }
        if (i == s.size() - 1)
          tlen[s[i] - 'a'] = max(tlen[s[i] - 'a'], (long long)cur);
      }
      for (int i = 0; i < 26; i++) {
        if (len[i] == 0) {
          len[i] = tlen[i];
          continue;
        }
        if (i != pre.first && i != suf.first)
          len[i] = max(tlen[i], (long long)1);
        else {
          if (i == pre.first && i == suf.first)
            len[i] = max(
                (long long)pre.second + (long long)suf.second + (long long)1,
                tlen[i]);
          else if (i == pre.first)
            len[i] = max((long long)pre.second + (long long)1, tlen[i]);
          else if (i == suf.first)
            len[i] = max((long long)suf.second + (long long)1, tlen[i]);
        }
      }
    }
  }
  long long ans = (long long)1;
  for (int i = 0; i < 26; i++) ans = max(ans, len[i]);
  cout << ans << '\n';
}
