local n, m = io.read("*n", "*n")
local a = {}
for i = 1, m do
  table.insert(a, io.read("*n"))
end
if(m <= n) then print(0) else
  table.sort(a)
  local ret = a[#a] - a[1]
  local diff = {}
  for i = 2, m do
    diff[i - 1] = a[i] - a[i - 1]
  end
  table.sort(diff, function(x, y) return x > y end)
  for i = 1, n - 1 do
    ret = ret - diff[i]
  end
  print(ret)
end
