(
  stdin.ReadLine() |> fun x -> x.Split(' ') |> Array.map int |> fun x -> (x.[0], x.[1]),
  stdin.ReadLine() |> fun x -> x.Split(' ') |> Array.map int
)
|> fun ((n, k), buildings) ->
  [0..((1 <<< (n - 1)) - 1)]
  |> List.map (
    fun candidates ->
        [0..(n - 2)]
        |> List.fold (
            fun (prev, num, cost) i ->
              buildings.[i + 1]
              |> fun ai ->
                if prev < ai
                then (ai, num + 1, cost)
                else (
                  if candidates >>> i &&& 1 = 1
                  then (prev + 1, num + 1, cost + (prev - ai + 1))
                  else (prev, num, cost)
                )
        ) (buildings.[0], 1, 0)
  )
  |> List.filter (fun (_, num, _) -> num >= k)
  |> List.map (fun (_, _, cost) -> cost)
  |> List.min
|> printfn "%d"
