n, m = gets.chop.split.map(&:to_i)
x = gets.chop.split.map(&:to_i)
p 0 if n >= m
if n < m
  x = x.sort
  d = []
  x.each_with_index do |pos, i|
    d.push(x[i+1] - x[i]) if x[i+1] != nil
  end
  n.times do |i|
    #p "d: #{d}"
    max = d.max
    index = d.index(max)
    d.delete_at(index) if i % 2 != 0 && i != 0
    if i == n - 1
      d.delete_at(index) if n % 2 != 0
      p d.inject(:+)
      return
    end
  end
end