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;
const int maxn = 1e5 + 70;
const int INF = 2.1e9;
const int MOD = 1e9 + 7;
const double eps = 1e-7;
const double PI = acos(-1.0);
int n, m, k;
int num[26];
int pre[26], sur[26], num2[26];
int main() {
  while (cin >> n) {
    string s;
    int cnt;
    cin >> s;
    memset(num, 0, sizeof(num));
    for (int i = 0; i < s.length(); i++) {
      if (!i || s[i] != s[i - 1])
        cnt = 1;
      else
        cnt++;
      num[s[i] - 'a'] = max(num[s[i] - 'a'], cnt);
    }
    n--;
    while (n--) {
      cin >> s;
      memset(num2, 0, sizeof(num2));
      memset(pre, 0, sizeof(pre));
      memset(sur, 0, sizeof(sur));
      bool flag = 1;
      for (int i = 0; i < s.length(); i++) {
        if (s[i] != s[0]) flag = 0;
        if (!i || s[i] != s[i - 1])
          cnt = 1;
        else
          cnt++;
        num2[s[i] - 'a'] = max(num2[s[i] - 'a'], cnt);
      }
      for (int i = 0; i < s.length(); i++) {
        if (s[i] == s[0])
          pre[s[0] - 'a']++;
        else
          break;
      }
      for (int i = s.length() - 1; i >= 0; i--) {
        if (s[i] == s[s.length() - 1])
          pre[s[s.length() - 1] - 'a']++;
        else
          break;
      }
      if (flag) {
        for (int i = 0; i < 26; i++) {
          if (s[0] - 'a' == i) {
            num[i] = (num[i] + 1) * s.length() + num[i];
          } else
            num[i] = (num[i] > 0);
        }
      } else {
        for (int i = 0; i < 26; i++) {
          num[i] = max((num[i] > 0) * (pre[i] + sur[i] + 1), num2[i]);
        }
      }
    }
    int ans = *max_element(num, num + 26);
    cout << ans << endl;
  }
  return 0;
}
