main=do
 [n,k]<-map read.words<$>getLine
 x<-map read.words<$>getLine
 print(f x n k 1000000000)
  where f x n k i =if n<k then i else (f (tail x) (n-1) k (min i (((x!!(k-1))-(x!!0))+(abs (head x)))))