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;
string s[100001];
long long n, k, k1, k2;
char c, d;
pair<long long, long long> a[27];
int main() {
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> s[i];
  for (long long i = 1; i < n; i++) {
    c = s[i][0];
    k = 1;
    for (long long j = 1; j <= s[i].size(); j++)
      if (s[i][j] == c)
        k++;
      else {
        a[c - 'a' + 1].first = max(a[c - 'a' + 1].first, k);
        k = 1;
        c = s[i][j];
      }
    c = s[i + 1][0];
    k = 1;
    for (long long j = 1; j <= s[i + 1].size(); j++) {
      if (s[i + 1][j] == c)
        k++;
      else {
        a[c - 'a' + 1].second = max(a[c - 'a' + 1].second, k);
        k = 1;
        c = s[i + 1][j];
      }
      c = s[i + 1][0];
      k1 = 1;
      for (long long j = 1; j <= s[i + 1].size(); j++)
        if (s[i + 1][j] == c)
          k1++;
        else
          break;
      d = s[i + 1][s[i + 1].size() - 1];
      k2 = 1;
      for (long long j = s[i + 1].size() - 2; j > -1; j--)
        if (s[i + 1][j] == d)
          k2++;
        else
          break;
      if (k1 == s[i + 1].size()) {
        a[c - 'a' + 1].first =
            (a[c - 'a' + 1].first + 1) * k1 + a[c - 'a' + 1].first;
        for (long long j = 1; j <= 26; j++) {
          if (j != c - 'a' + 1 && a[j].first != 0) a[j].first = 1;
          a[j].second = 0;
        }
      } else {
        if (c == d) {
          if (a[c - 'a' + 1].first == 0)
            a[c - 'a' + 1].first = max(k1, k2);
          else
            a[c - 'a' + 1].first = k1 + k2 + 1;
          for (long long j = 1; j <= 26; j++)
            if (j != c - 'a' + 1 && a[j].first != 0) a[j].first = 1;
          for (long long j = 1; j <= 26; j++)
            a[j].first = max(a[j].first, a[j].second);
          for (int j = 1; j <= 26; j++) a[j].second = 0;
        } else {
          if (a[c - 'a' + 1].first == 0)
            a[c - 'a' + 1].first = k1;
          else
            a[c - 'a' + 1].first = k1 + 1;
          if (a[d - 'a' + 1].first == 0)
            a[d - 'a' + 1].first = k2;
          else
            a[d - 'a' + 1].first = k2 + 1;
          for (long long j = 1; j <= 26; j++)
            if (j != c - 'a' + 1 && a[j].first != 0 && j != d - 'a' + 1)
              a[j].first = 1;
          for (int j = 1; j <= 26; j++)
            a[j].first = max(a[j].first, a[j].second);
          for (long long j = 1; j <= 26; j++) a[j].second = 0;
        }
      }
    }
  }
  k = 0;
  for (long long i = 1; i <= 26; i++) k = max(k, a[i].first);
  cout << k;
  return 0;
}
