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;
const int MAXN = 100005;
string s[MAXN];
set<char> ss[MAXN];
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = n; i >= 1; i--) {
    cin >> s[i];
    int l = s[i].length();
    for (int j = 0; j < l; j++) {
      ss[i].insert(s[i][j]);
    }
  }
  int head = 1, tail = 1, ans = 1;
  char ch1 = s[1][0], ch2 = s[1][s[1].size() - 1];
  bool flag = false;
  if (ss[1].size() == 1) {
    flag = true;
    ans = head = tail = s[1].size();
  } else {
    int l = s[1].size();
    for (int i = 1; i < l; i++) {
      if (s[1][i] != s[1][0]) break;
      head++;
    }
    ans = max(head, ans);
    for (int i = l - 2; i >= 0; i--) {
      if (s[1][i] != s[1][l - 1]) break;
      tail++;
    }
    ans = max(tail, ans);
    int cnt = 1;
    for (int i = 1; i < l; i++) {
      if (s[1][i] == s[1][i - 1]) {
        cnt++;
        ans = max(ans, cnt);
      } else
        cnt = 1;
    }
  }
  if (n == 2 && s[n].size() >= 200)
    cout << head << ' ' << tail << ' ' << ' ' << ch1 << ' ' << ch2 << ' ' << ans
         << ' ' << flag << ' ' << s[1] << endl;
  for (int i = 2; i <= n; i++) {
    string &str = s[i];
    int l = str.size();
    if (flag && ss[i].size() == 1 && str[0] == ch1) {
      head = tail = (l + 1) * head + l;
    } else {
      flag = false;
      if (ch1 == ch2) {
        if (ss[i].count(ch1)) ans = max(ans, head + tail + 1);
      }
      if (ss[i].count(ch1)) {
        ans = max(ans, head + 1);
      }
      if (ss[i].count(ch2)) {
        ans = max(ans, tail + 1);
      }
    }
  }
  ans = max(ans, max(head, tail));
  cout << ans << endl;
}
