f 0 c _ _ = c
f _ _ _ [] = 1/0
f k c p (a:as)
  | p < a = f (k-1) c a as
  | otherwise = f k c p as `min` f (k-1) (c+p+1-a) (p+1) as
main = do
  [n,k] <- map read . words <$> getLine
  (a:as) <- map read . words <$> getLine
  print $ floor $ f (k-1) 0 a as