n,m,*d=$<.read.split.map &:to_i d.sort! p (n..m).map{|i|x,y=d[i-n],d[i-1];y<0?-x:x>0?y:[y-x*2,y*2-x].min}.min