import Data.List
f :: [String]->[String]
f []=[]
f (x:xs)=if elem '#' x then x:f xs else f xs

f3::Int->Int->Int
f3 l r
   |r<=0 = -l
   |0<=l = r
   |otherwise=(minimum [-l,r])+r-l

f2 ::[Int]->[Int]->Int->Int->[Int]
f2 _ [] _ ans=[]
f2 (x:xs) (y:ys) k ans
     |k>1=f2 (x:xs) ys (k-1) ans
     |otherwise=(f3 x y):f2 xs ys 0 ans
main = do 
       a<-getLine
       b<-getLine
       let (n:k:[])=(map read . words) a::[Int]
           xs=(map read .words) b ::[Int]
       putStrLn $ show $ minimum $ f2 xs xs k 2000000000 