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 Gcd(int a, int b) {
  if (b == 0) return a;
  return Gcd(b, a % b);
}
int Lcm(int a, int b) { return a / Gcd(a, b) * b; }
template <class T>
void read(T &x) {
  static char ch;
  static bool neg;
  for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar())
    ;
  for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar())
    ;
  x = neg ? -x : x;
}
const int maxn = 1e6 + 10;
char s[maxn];
stack<string> stk;
int main() {
  int n;
  read(n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    stk.push(s);
  }
  string tmp = stk.top();
  stk.pop();
  char st = tmp[0], ed = tmp[tmp.length() - 1];
  int len1 = 1, len2 = 1, len = 0, ans = 1;
  for (int i = 1; i < tmp.size(); i++) {
    if (st == tmp[i])
      len1++;
    else
      break;
  }
  for (int i = (int)tmp.size() - 1; i >= 0; i--) {
    if (ed == tmp[i])
      len2++;
    else
      break;
  }
  for (int i = 1; i < tmp.size(); i++) {
    if (tmp[i] == tmp[i - 1])
      len++;
    else
      ans = max(ans, len);
  }
  ans = max(ans, len);
  while (!stk.empty()) {
    string tmp = stk.top();
    stk.pop();
    if (ans == len1) {
      int cnt = 0, cnt1 = 0, cnt2 = 0;
      for (int i = 0; i < tmp.length(); i++) {
        if (tmp[i] == st) {
          cnt++;
        } else {
          ans = max(ans, (cnt + 1) * len1 + cnt);
        }
      }
      ans = max(ans, (cnt + 1) * len1 + cnt);
      for (int i = 0; i < tmp.size(); i++) {
        if (st == tmp[i])
          cnt1++;
        else
          break;
      }
      len1 = (cnt1 + 1) * len1 + cnt1;
      for (int i = (int)tmp.size() - 1; i >= 0; i--) {
        if (ed == tmp[i])
          cnt2++;
        else
          break;
      }
      len2 = (cnt2 + 1) * len2 + cnt2;
    } else {
      for (int i = 0; i < tmp.size(); i++) {
        int len = 1;
        if (tmp[i] == st) len += len1;
        if (tmp[i] == ed) len += len2;
        ans = max(len, ans);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
