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 = (int)1e5 + 5;
const int mod = (int)1e9 + 7;
int n, m, k, l, s, t, r, ans, T;
int a[maxn];
string p[maxn];
int len[maxn];
int vis[maxn];
int last[maxn];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> p[i], len[i] = p[i].length();
  int flag = 0;
  for (int i = 1; i < len[n]; i++)
    if (p[n][i] != p[n][i - 1]) {
      flag = 1;
      break;
    }
  if (flag == 1) {
    for (int i = 1; i < n; i++)
      for (int j = 0; j < len[i]; j++) vis[p[i][j]] = 1;
    last[0] = 1;
    for (int i = 1; i < len[n]; i++)
      if (p[n][i] == p[n][i - 1])
        last[i] = last[i - 1] + 1;
      else
        last[i] = 1;
    for (int i = 0; i < len[n]; i++) ans = max(ans, last[i]);
    for (int i = 0; i < len[n]; i++)
      if (last[i + 1] == 1) {
        k = last[i];
        break;
      }
    if (p[n][0] == p[n][len[n] - 1]) {
      if (vis[p[n][0]]) cout << max(ans, k + last[len[n] - 1] + 1);
    } else {
      if (vis[p[n][0]]) ans = max(ans, k + 1);
      if (vis[p[n][len[n] - 1]]) ans = max(ans, last[len[n] - 1] + 1);
      cout << ans << endl;
    }
    cout << endl;
  } else {
    int chn = p[n][0];
    for (int i = n; i >= 1; i--) {
      memset(last, 0, sizeof(last));
      last[0] = 1;
      for (int j = 1; j < len[i]; j++)
        if (p[i][j] == p[i][j - 1])
          last[j] = last[j - 1] + 1;
        else
          last[j] = 1;
      if (last[len[i] - 1] != len[i] || p[i][0] != chn) {
        k = i;
        break;
      }
    }
    if (k == 0) {
      ans = len[1];
      k = 1;
    } else {
      for (int i = 0; i < len[k]; i++)
        if (p[k][i] == chn) ans = max(ans, last[i]);
      for (int i = 1; i < k; i++)
        for (int j = 0; j < len[i]; j++) vis[p[i][j]] = 1;
      if (vis[chn]) ans = 1;
      if (p[k][0] == chn)
        for (int i = 0; i < len[n]; i++)
          if (last[i + 1] == 1) {
            r = last[i];
            break;
          }
      if (p[k][0] == p[k][len[k] - 1] && p[k][0] == chn) {
        if (vis[p[k][0]]) ans = max(ans, r + last[len[k] - 1] + 1);
      } else {
        if (vis[p[k][0]] && p[k][0] == chn) ans = max(ans, r + 1);
        if (vis[p[k][len[k] - 1]] && p[k][len[k] - 1] == chn)
          ans = max(ans, last[len[k] - 1] + 1);
      }
      for (int i = k + 1; i <= n; i++) ans = ans + (ans + 1) * len[i];
      cout << ans << endl;
    }
  }
  return 0;
}
