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;
vector<string> v;
int get(char k, int m) {
  int l = 0, r = 0;
  string s = v[m];
  int sz = s.size();
  while (l < sz) {
    if (s[l] == k)
      ++l;
    else
      break;
  }
  while (r < sz) {
    if (s[sz - r - 1] == k)
      ++r;
    else
      break;
  }
  int t = 0;
  int mx = 0;
  for (int i = 0; i < sz; ++i) {
    if (s[i] == k)
      ++t;
    else {
      if (t > mx) mx = t;
      t = 0;
    }
  }
  mx = std::max(mx, t);
  int q = max(l, r);
  if (m == 0) return max(q, mx);
  int et = get(k, m - 1);
  if (mx == sz) return (et + 1) * mx + et;
  return max(mx, l + r + 1);
}
int main() {
  ios::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = (0); i < (n); i += (1)) {
    string t;
    cin >> t;
    v.push_back(t);
  }
  string s = v[n - 1];
  int t = 1;
  char c = s[0];
  int max = 1;
  for (int i = 1; i < s.size(); ++i) {
    if (c == s[i])
      ++t;
    else {
      if (max < t) max = t;
      t = 1;
      c = s[i];
    }
  }
  int l = 0, r = 0;
  int sz = s.size();
  while (l < sz) {
    if (s[l] == c)
      ++l;
    else
      break;
  }
  c = s[s.size() - 1];
  while (r < sz) {
    if (s[sz - r - 1] == c)
      ++r;
    else
      break;
  }
  max = std::max(max, t);
  int e = get(s[0], n - 2);
  if (max == sz) {
    e += (e + 1) * max;
  } else if (s[0] == s[sz - 1]) {
    if (e > 0)
      e = l + r + 1;
    else
      e = std::max(l, r);
  } else {
    e = std::max(e + l, get(s[sz - 1], n - 2) + r);
  }
  cout << std::max(max, e);
  return 0;
}
