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 N = 1e5 + 5;
int n;
string s[N];
int main() {
  std::ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  long long ans = 0;
  for (int i = 0; i < 26; i++) {
    char c = i + 'a';
    int len = s[1].size();
    long long maxn = 0, summ = 0;
    for (int j = 0; j < len; j++) {
      if (s[1][j] == c)
        if (j == 0 || s[1][j] == s[1][j - 1])
          summ = summ + 1;
        else
          summ = 1;
      maxn = max(maxn, summ);
    }
    for (int j = 2; j <= n; j++) {
      len = s[j].size();
      int num = 0;
      for (int k = 0; k < len; k++)
        if (s[j][k] == c) num++;
      if (num == len) {
        maxn = maxn + (maxn + 1) * len;
        continue;
      }
      long long L = 0, R = 0;
      for (int k = 0; k < len; k++)
        if (s[j][k] == c)
          L++;
        else
          break;
      for (int k = len - 1; k >= 0; k--)
        if (s[j][k] == c)
          R++;
        else
          break;
      if (maxn >= 1)
        maxn = L + 1 + R;
      else
        maxn = max(L, R);
    }
    ans = max(ans, maxn);
  }
  cout << ans;
}
