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;
signed solve();
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tests = 1;
  while (tests--) solve();
  return 0;
}
const int MAX_N = 1e5 + 5;
string t[MAX_N];
int len[MAX_N];
int pref[MAX_N], suf[MAX_N];
int kt[MAX_N][26], k[26];
signed solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> t[i];
    len[i] = t[i].size();
  }
  for (int i = 0; i < n; ++i) {
    {
      int j = 0;
      while (j < len[i] && t[i][0] == t[i][j]) ++j;
      pref[i] = j;
    }
    {
      int j = len[i] - 1;
      while (j > -1 && t[i][len[i] - 1] == t[i][j]) --j;
      suf[i] = len[i] - 1 - j;
    }
    char cur = t[i][0];
    int cur_k = 1;
    for (int j = 1; j < len[i]; ++j) {
      if (t[i][j] == cur) {
        ++cur_k;
      } else {
        kt[i][cur - 'a'] = max(kt[i][cur - 'a'], cur_k);
        cur = t[i][j];
        cur_k = 1;
      }
    }
    kt[i][cur - 'a'] = max(kt[i][cur - 'a'], cur_k);
  }
  for (int l = 0; l < 26; ++l) {
    k[l] = kt[0][l];
  }
  for (int i = 1; i < n; ++i) {
    if (len[i] == 1) {
      for (int l = 0; l < 26; ++l) {
        if (l == t[i][0] - 'a')
          k[l] += (k[l] > 0) + 1;
        else
          k[l] = int(k[l] > 0);
      }
    } else if (pref[i] == len[i]) {
      for (int l = 0; l < 26; ++l) {
        if (l == t[i][0] - 'a')
          k[l] = len[i] * (k[l] + 1) + (k[l] > 0);
        else
          k[l] = int(k[l] > 0);
      }
    } else if (t[i][0] == t[i][len[i] - 1]) {
      for (int l = 0; l < 26; ++l) {
        if (l == t[i][0] - 'a')
          k[l] = pref[i] + suf[i] + (k[l] > 0);
        else
          k[l] = max(int(k[l] > 0), kt[i][l]);
      }
    } else {
      for (int l = 0; l < 26; ++l) {
        if (l == t[i][0] - 'a')
          k[l] = kt[i][l] + (k[l] > 0);
        else if (l == t[len[i] - 1][0] - 'a')
          k[l] = kt[i][l] + (k[l] > 0);
        else
          k[l] = max(int(k[l] > 0), kt[i][l]);
      }
    }
  }
  int ans = 0;
  for (int l = 0; l < 26; ++l) {
    ans = max(ans, k[l]);
  }
  cout << ans << '\n';
  return 0;
}
