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
n = int(raw_input())
s = raw_input()
def get(s, c):
	w = 0
	p = -1
	r = 0
	for k in s:
		if k == c:
			w += 1
		else:
			w = 0
		r = max(r, w)
	return r

best = [get(s, chr(c+ord('a'))) for c in xrange(26)]
for i in xrange(1, n):
	si = raw_input()
	dd = ord(si[0]) - ord('a')
	if len(set(si)) == 1:
		best[dd] = len(si) * (best[dd] + 1) + best[dd]
	elif si[0] == si[-1]:
		f1 = 0
		f2 = 0
		while si[f1] == si[0]:
			f1 += 1
		while si[-i-f2] == si[0]:
			f2 += 1
		if best[dd] > 0:
			best[dd] = f1 + f2 + 1
		else:
			best[dd] = max(f1, f2)
	else:
		best[dd] = get(si, chr(dd+ord('a')))

	for c in xrange(26):
		if c != dd:
			best[c] = get(si, chr(c+ord('a')))

print max(best)