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
def prog(mass, st):
    global alf
    if st == st[0] * len(st):
        for i in range(26):
            if alf[i] == st[0]:
                mass[i] = (mass[i] + 1) * len(st) + mass[i]
            else:
                mass[i] = min(1, mass[i])
    else:
        mmm = razlog(st)
        r = 1
        while st[r] == st[r - 1]:
            r += 1
        k = 1
        while st[len(st) - k] == st[len(st) - k - 1]:
            k += 1
        for i in range(26):
            if alf[i] == st[0] and alf[i] == st[-1]:
                if mass[i] == 0:
                    mass[i] = max(mmm[i], k, r)
                else:
                    mass[i] = max(mmm[i], k + r + 1)
            elif alf[i] == st[0]:
                if mass[i] == 0:
                    mass[i] = max(mmm[i], r)
                else:
                    mass[i] = max(mmm[i], r + 1)
            elif alf[i] == st[-1]:
                if mass[i] == 0:
                    mass[i] = max(mmm[i], k)
                else:
                    mass[i] = max(mmm[i], k + 1)
            else:
                if mass[i] == 0:
                    mass[i] = mmm[i]
                else:
                    mass[i] = max(1, mmm[i])
    return mass
        
        

def razlog(st):
    global alf
    mass = [0 for i in range(26)]
    mass[alf.index(st[0])] = 1    
    now = 1
    for i in range(1, len(st)):
        if st[i] == st[i - 1]:
            now += 1
        else:
            now = 1
        mass[alf.index(st[i])] = max(now, mass[alf.index(st[i])])
    return mass 

n = int(input())
st = input()
alf = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
mass = razlog(st)
for i in range(n - 1):
    sti = input()
    mass = prog(mass, sti)
print(max(mass))