change N-1 to N

if line is vertical， it will not work with N-1.