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
s = []

def go(idx, c):
	p = 0
	while((p < len(s[idx])) and (s[idx][p] == c)):
		p += 1
	l = p
	p = len(s[idx]) - 1
	while((p >= 0) and (s[idx][p] == c)):
		p -= 1
	r = len(s[idx]) - 1 - p
	
	high, cur = 0, 0
	for i in range(len(s[idx])):
		if(s[idx][i] == c):
			cur += 1
		else:
			high = max(cur, high)
			cur = 0
	
	high = max(cur, high)
	return high, l, r

n = [int(x) for x in raw_input().split()][0]
for _ in range(n):
	word = str(raw_input())
	s.append(word)

dp = [0 for _ in range(n)]
ans = 0
for cc in range(ord('a'), ord('z') + 1):
	c = chr(cc)
	dp[0], l, r = go(0, c)
	for i in range(1, n):
		ret, l, r = go(i, c)
		if(ret == len(s[i])):
			dp[i] = dp[i - 1] * ret + ret + dp[i - 1]
		else:
			if(dp[i-1] == 0): 
				dp[i] = max(l, r)
			else:
				dp[i] = l + r + 1
		ans = max(ans, dp[n-1])
	
print(ans)
