local mmi, mma = math.min, math.max
local function combination_get_map(n)
  local combmap = {}
  for i = 1, n do
    combmap[i] = {}
    local ret = 1
    for j = 1, i do
      ret = ret * (i + 1 - j) // j
      combmap[i][j] = ret
    end
  end
  return combmap
end
local function combination_get_count(combmap, n, k)
  if k < 0 then return 0
  elseif n < k then return 0
  elseif k == 0 then return 1
  else return combmap[n][k]
  end
end

local function combination_get_array(combmap, n, k, idx)
  local rem = k
  local retary = {}
  for i = 1, n do
    local useCnt = combination_get_count(combmap, n - i, rem - 1)
    local unuseCnt = combination_get_count(combmap, n - i, rem)
    if idx <= useCnt then
      rem = rem - 1
      table.insert(retary, i)
    else
      idx = idx - useCnt
    end
  end
  return retary
end

local n, k = io.read("*n", "*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local cmap = combination_get_map(n)
local tot = combination_get_count(cmap, n, k)
local mincost = 1000000007 * 100
for i = 1, tot do
  local cost = 0
  local ary = combination_get_array(cmap, n, k, i)
  local height = a[1]
  for j = 2, ary[1] do
    height = mma(height, a[j])
  end
  for j = 2, k do
    local v = a[ary[j]]
    if height < v then
      height = v
    else
      cost = cost + height + 1 - v
      height = height + 1
    end
  end
  mincost = mmi(mincost, cost)
end
print(mincost)
