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;
long long int mul(long long int x, long long int y) {
  long long int ans = 1;
  while (y > 0) {
    if (y & 1) ans = (ans * x) % 1000000007;
    y /= 2;
    x = (x * x) % 1000000007;
  }
  return ans;
};
vector<long long int> fun(string str) {
  long long int i, size = str.size(), cnt = 0;
  vector<long long int> h(26, 0);
  h[str[0] - 'a'] = 1;
  cnt = 1;
  for (i = 1; i < size; i++) {
    if (str[i] == str[i - 1])
      ++cnt;
    else
      cnt = 1;
    h[str[i] - 'a'] = max(cnt, h[str[i] - 'a']);
  }
  return h;
}
long long int start_cnt(string str) {
  long long int i, size = str.size(), cnt = 1;
  for (i = 1; i < size; i++)
    if (str[i] == str[0])
      ++cnt;
    else
      break;
  return cnt;
}
long long int end_cnt(string str) {
  long long int i, size = str.size(), cnt = 1;
  for (i = size - 2; i >= 0; i--)
    if (str[i] == str[size - 1])
      ++cnt;
    else
      break;
  return cnt;
}
void pp(vector<long long int> v) {
  long long int i, size = v.size();
  for (i = 0; i < size; i++) cout << v[i] << " ";
  cout << "\n";
  return;
}
int main() {
  long long int n, i, size, aa, bb, j;
  string str;
  scanf("%lld", &n);
  vector<long long int> ans, last;
  for (i = 1; i <= n; i++) {
    cin >> str;
    size = str.size();
    ans = fun(str);
    aa = start_cnt(str);
    bb = end_cnt(str);
    if (i > 1) {
      for (j = 0; j < 26; j++)
        if (last[j] > 0 && ans[j] == 0) ans[j] = 1;
      if (size == aa)
        ans[str[0] - 'a'] =
            (last[str[0] - 'a'] + 1) * size + last[str[0] - 'a'];
      else if (str[0] == str[size - 1] && last[str[0] - 'a'] > 0)
        ans[str[0] - 'a'] = max(ans[str[0] - 'a'], bb + 1 + aa);
      else {
        if (last[str[0] - 'a'] > 0)
          ans[str[0] - 'a'] = max(ans[str[0] - 'a'], 1 + aa);
        if (last[str[size - 1] - 'a'] > 0)
          ans[str[size - 1] - 'a'] = max(ans[str[size - 1] - 'a'], bb + 1);
      }
    }
    last = ans;
  }
  long long int fin = 0;
  for (i = 0; i < 26; i++) fin = max(fin, last[i]);
  cout << fin << "\n";
  return 0;
}
