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 long long N = 1e5 + 7;
int dp[30];
char s[N];
bool vis[N];
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s);
    int len = strlen(s);
    vis[s[0] - 'a'] = true;
    bool flag = true;
    for (int i = 1; i < len; i++) {
      vis[s[i] - 'a'] = true;
      if (s[i] != s[i - 1]) flag = false;
    }
    if (flag) {
      int i = s[0] - 'a';
      dp[i] = (dp[i] + 1) * len + dp[i];
      for (int j = 0; j < 26; j++) {
        if (j == i) continue;
        if (vis[j]) dp[j] = 1;
      }
    } else {
      for (int i = 0; i < 26; i++) {
        int cnt1 = 0, cnt2 = 0;
        for (int j = 0; j < len; j++) {
          if (s[j] == 'a' + i)
            cnt1++;
          else
            break;
        }
        for (int j = len - 1; j > 0; j--) {
          if (s[j] == 'a' + i)
            cnt2++;
          else
            break;
        }
        if (dp[i] == 0)
          dp[i] = max(cnt1, cnt2);
        else {
          dp[i] = cnt1 + cnt2 + 1;
        }
        int tmp = 0;
        for (int j = 0; j < len; j++) {
          if (s[j] == 'a' + i)
            tmp++;
          else
            dp[i] = max(dp[i], tmp), tmp = 0;
        }
        dp[i] = max(dp[i], tmp);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    ans = max(ans, dp[i]);
  }
  printf("%d\n", ans);
  return 0;
}
