input = STDIN.readline.split()
n = input[0].to_i
m = input[1].to_i
x_list = STDIN.readline.split().map{|x|x.to_i}
min = 100000
max = -100000
x_exists = {}
for x in x_list do
    if x < min then
        min = x
    end
    if x > max then
        max = x
    end
    x_exists[x] = 1
end
diff_counts = {}
diff_max = 0
c = 0
for i in Range.new(min + 1, max) do
    c += 1
    if x_exists.has_key?(i) then
        if diff_counts.has_key?(c) then
            diff_counts[c] += 1
        else
            diff_counts[c] = 1
        end
        if c > diff_max then
            diff_max = c
        end
        c = 0
    end
end

sum = 0
for i in Range.new(1, diff_max) do
    if diff_counts.has_key?(i) then
        while m > n && diff_counts[i] > 0 do
            m -= 1
            diff_counts[i] -= 1
            sum += i
        end
    end
end
puts(sum)