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>
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
using namespace std;
int n, m;
string s;
long long dp[30];
long long a[30];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  long long ans = 1;
  for (int z = 1; z <= n; ++z) {
    cin >> s;
    bool flag = 1;
    int len = s.length();
    for (int j = 1; s[j]; ++j)
      if (s[j] != s[0]) {
        flag = 0;
        break;
      }
    if (flag) {
      int id = s[0] - 'a';
      for (int k = 0; k < 26; ++k) {
        if (k == id) continue;
        if (dp[k]) dp[k] = 1;
      }
      dp[id] = max(dp[id], min(1000000000LL, (dp[id] + 1) * len + dp[id]));
    } else {
      long long e = 1;
      memset(a, 0, sizeof(a));
      s += 'Z';
      for (int i = 1; i <= len; ++i) {
        if (s[i - 1] == s[i])
          e++;
        else {
          a[s[i - 1] - 'a'] = max(a[s[i - 1] - 'a'], e);
          e = 1;
        }
      }
      long long l = 1, r = 1;
      for (int i = 1; i < len; ++i) {
        if (s[i] == s[0])
          l++;
        else
          break;
      }
      for (int i = len - 2; i > 0; --i) {
        if (s[i] == s[len - 1])
          r++;
        else
          break;
      }
      a[s[0] - 'a'] = max(a[s[0] - 'a'], l + (dp[s[0] - 'a'] >= 1 ? 1 : 0));
      a[s[len - 1] - 'a'] =
          max(a[s[len - 1] - 'a'], r + (dp[s[len - 1] - 'a'] >= 1 ? 1 : 0));
      if (s[0] == s[len - 1] && dp[s[0] - 'a'] >= 1)
        a[s[0] - 'a'] = max(a[s[0] - 'a'], l + r + 1);
      for (int i = 0; i < 26; ++i) dp[i] = min(1000000000LL, max(dp[i], a[i]));
    }
  }
  for (int i = 0; i < 26; ++i) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}
