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;
int main() {
  int n, p = 0;
  string s;
  vector<int> a(26);
  cin >> n >> s;
  --n;
  for (int i = 1; i < (int)s.size(); ++i) {
    if (s[i] != s[i - 1]) {
      a[s[i - 1] - 'a'] = max(a[s[i - 1] - 'a'], i - p);
      p = i;
    }
  }
  a[s.back() - 'a'] = max(a[s.back() - 'a'], (int)s.size() - p);
  for (int i = 0; i < n; ++i) {
    cin >> s;
    bool isoneletter = true;
    for (int j = 1; j < (int)s.size(); ++j) {
      if (s[j] != s[j - 1]) {
        isoneletter = false;
        break;
      }
    }
    if (isoneletter) {
      for (int i = 0; i < 26; ++i) {
        if (s[0] - 'a' == i) {
          a[i] += (a[i] + 1) * (int)s.size();
        } else {
          a[i] = min(a[i], 1);
        }
      }
    } else {
      int left = 1, right = 1;
      for (int i = 1; i < (int)s.size(); ++i) {
        if (s[i] != s[i - 1]) break;
        ++left;
      }
      for (int i = (int)s.size() - 2; i >= 0; --i) {
        if (s[i] != s[i + 1]) break;
        ++right;
      }
      if (s[0] == s[(int)s.size() - 1]) {
        if (a[s[0] - 'a'] > 0) {
          a[s[0] - 'a'] = 1 + left + right;
        }
      } else {
        if (a[s[0] - 'a'] > 0) {
          a[s[0] - 'a'] = 1 + left;
        }
        if (a[s[(int)s.size() - 1] - 'a'] > 0) {
          a[s[(int)s.size() - 1] - 'a'] = 1 + right;
        }
      }
    }
    p = 0;
    for (int i = 1; i < (int)s.size(); ++i) {
      if (s[i] != s[i - 1]) {
        a[s[i - 1] - 'a'] = max(a[s[i - 1] - 'a'], i - p);
        p = i;
      }
    }
    a[s.back() - 'a'] = max(a[s.back() - 'a'], (int)s.size() - p);
  }
  cout << *max_element(a.begin(), a.end()) << endl;
  return 0;
}
