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 n;
string p[100000];
bool all_same(string s) {
  for (char c : s) {
    if (c != s[0]) return false;
  }
  return true;
}
bool contains(string s, char c) {
  for (char i : s) {
    if (c == i) return true;
  }
  return false;
}
int head_len(string s) {
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != s[0]) return i;
  }
  return s.size();
}
int tail_len(string s) {
  int sz = s.size();
  for (int i = 0; i < sz; i++) {
    if (s[sz - i - 1] != s[sz - 1]) return i;
  }
  return s.size();
}
int calc_max_same(string s) {
  char c = s[0];
  int cnt = 1;
  int ans = 0;
  for (int i = 1; i < s.size(); i++) {
    if (c != s[i]) {
      ans = max(ans, cnt);
      c = s[i];
      cnt = 1;
    } else {
      cnt++;
    }
  }
  ans = max(ans, cnt);
  return ans;
}
int calc_max_len(string s, char c) {
  int cnt = 0;
  int ans = 0;
  for (char i : s) {
    if (i == c)
      cnt++;
    else
      cnt = 0;
    ans = max(ans, cnt);
  }
  return ans;
}
void solve_all_same() {
  int cur = 0;
  for (int i = 1; i < n; i++) {
    if (!all_same(p[i])) break;
    if (p[i][0] != p[0][0]) break;
    cur = i;
  }
  int len = p[0].size();
  for (int i = 1; i <= cur; i++) {
    len = len * (p[i].size() + 1) + p[i].size();
  }
  int ans = len;
  if (n == 301) cout << len << endl;
  for (int i = cur + 1; i < n; i++) {
    int tmp = calc_max_len(p[i], p[0][0]);
    ans = max(ans, len * (tmp + 1) + tmp);
  }
  cout << ans << endl;
}
void solve_same_head_tail() {
  int ans = calc_max_same(p[0]);
  int head = head_len(p[0]);
  int tail = tail_len(p[0]);
  for (int i = 1; i < n; i++) {
    if (contains(p[i], p[0][0])) {
      cout << head + tail + 1 << endl;
      return;
    }
  }
  cout << ans << endl;
}
void solve_else() {
  int ans = calc_max_same(p[0]);
  int head = head_len(p[0]);
  int tail = tail_len(p[0]);
  for (int i = 1; i < n; i++) {
    if (contains(p[i], p[0][0])) {
      ans = max(ans, head + 1);
    }
    if (contains(p[i], p[0][p[0].size() - 1])) {
      ans = max(ans, tail + 1);
    }
  }
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(10) << fixed;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[n - i - 1];
  }
  int sz = p[0].size();
  if (all_same(p[0])) {
    solve_all_same();
  } else if (p[0][0] == p[0][sz - 1]) {
    solve_same_head_tail();
  } else {
    solve_else();
  }
}
