n,m,*d=$<.read.split.map &:to_i p d.each_cons(n).map{|e| x,y=e[0],e[-1] y<0 ? -x : x>0 ? y : y-x+[y,-x].min }.min