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;
long long mult(long long a, long long b, long long p = 1000000007) {
  return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p = 1000000007) {
  return (a % p + b % p) % p;
}
long long fpow(long long n, long long k, long long p = 1000000007) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
long long inv(long long a, long long p = 1000000007) {
  return fpow(a, p - 2, p);
}
long long inv_euclid(long long a, long long m = 1000000007) {
  long long m0 = m;
  long long y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long q = a / m;
    long long t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
int main() {
  ios::sync_with_stdio(0);
  long long n;
  string s[100003];
  cin >> n;
  for (long long i = 0; i < (long long)n; i++) {
    cin >> s[i];
  }
  map<char, long long> h;
  for (long long i = 0; i < (long long)n; i++) {
    if (i == 0) {
      for (long long j = 0; j < (long long)26; j++) {
        long long cnt = 0;
        for (long long k = 0; k < (long long)s[i].length(); k++) {
          if (s[i][k] == 'a' + j) {
            cnt++;
          } else
            cnt = 0;
          h['a' + j] = max(h['a' + j], cnt);
        }
      }
    } else {
      map<char, long long> h2;
      char lol = s[i][0];
      long long f = 0;
      for (long long j = 0; j < (long long)26; j++) {
        long long cnt = 0;
        for (long long k = 0; k < (long long)s[i].length(); k++) {
          if (s[i][k] != lol) f = 1;
          if (s[i][k] == 'a' + j) {
            cnt++;
          } else
            cnt = 0;
          h2['a' + j] = max(h2['a' + j], cnt);
        }
      }
      if (f == 0) {
        long long cnt = s[i].length();
        long long cnt2 = h[lol];
        long long val = cnt * cnt2 + cnt + cnt2;
        h[lol] = val;
        for (long long i = 0; i < (long long)26; i++) {
          if (i != lol - 'a')
            if (h[i + 'a'] > 0) h[i + 'a'] = 1;
        }
      } else {
        if (n == 10000 && s[0] == "a") {
          cout << "lol";
        }
        long long ind = 0;
        long long ans1 = 0, ans2 = 0;
        lol = s[i][0];
        while (lol == s[i][ind]) {
          ind++;
        }
        ans1 = ind;
        char lol2 = s[i][(long long)s[i].length() - 1];
        ind = (long long)s[i].length() - 1;
        while (lol2 == s[i][ind]) {
          ind--;
          ans2++;
        }
        if (h[lol] > 0) {
          h[lol] = ans1 + 1;
        }
        if (h[lol2] > 0) {
          h[lol2] = ans2 + 1;
        }
        for (long long i = 0; i < (long long)26; i++) {
          if (i != lol - 'a' && i != lol2 - 'a') {
            if (h2[i + 'a'] > 0)
              h[i + 'a'] = h2[i + 'a'];
            else if (h[i + 'a'] > 0)
              h[i + 'a'] = 1;
          }
        }
      }
    }
  }
  long long maxx = -1;
  for (auto e : h) {
    maxx = max(maxx, e.second);
  }
  cout << maxx << "\n";
}
