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;
string s[100005];
int cd, st[100005], got[300], en[100005], mx[100005][300];
void prepare(int id) {
  int cur = s[id][1];
  int got = 1;
  for (int i = 1; i < s[id].size(); i++) {
    if (s[id][i] != cur || i == s[id].size() - 1) {
      cur = s[id][i];
      mx[id][s[id][i]] = max(mx[id][s[id][i]], got);
      got = 1;
    } else {
      got++;
    }
  }
  int i = 1;
  while (i < s[id].size() && s[i] == s[1]) {
    st[id]++;
    i++;
  }
  i = s[id].size() - 1;
  while (i > 0 && s[i] == s[s[id].size() - 1]) {
    en[id]++;
    i--;
  }
}
int main() {
  cin >> cd;
  for (int i = 1; i <= cd; i++) {
    cin >> s[i];
    s[i] = '0' + s[i];
    prepare(i);
  }
  for (int i = 'a'; i <= 'z'; i++) {
    got[i] = mx[1][i];
    if (got[i] != 0) {
    }
  }
  for (int i = 2; i <= cd; i++) {
    int fir = s[i][1], las = s[i][s[i].size() - 1];
    if (mx[i][fir] == s[i].size() - 1) {
      got[fir] = (got[fir] + 1) * mx[i][fir] + got[fir];
    } else if (fir == las) {
      for (int e = 'a'; e <= 'z'; e++) {
        if (got[e] != 0) {
          got[e] = 1;
        }
      }
      for (int e = 'a'; e <= 'z'; e++) {
        if (e != fir) {
          got[e] = mx[i][e];
        }
      }
      if (got[fir] != 0) {
        got[fir] = max(mx[i][fir], 1 + st[i] + en[i]);
      } else {
        got[fir] = mx[i][fir];
      }
    } else {
      for (int e = 'a'; e <= 'z'; e++) {
        if (got[e] != 0) {
          got[e] = 1;
        }
      }
      for (int e = 'a'; e <= 'z'; e++) {
        if (e != las && e != fir) {
          got[e] = mx[i][e];
        }
      }
      got[fir] = max(mx[i][fir], st[i] + min(1, got[fir]));
      got[las] = max(mx[i][las], en[i] + min(1, got[las]));
    }
  }
  int kq = 0;
  for (int i = 'a'; i <= 'z'; i++) {
    kq = max(kq, got[i]);
  }
  cout << kq << '\n';
}
