function Main(input) {
  const data = input.trim().split('\n')
  const N = data[0].split(' ').map(s => parseInt(s))[0]
  const rest = data[1].split(' ').map(s => parseInt(s)).sort((a, b) => a - b)

  const DIV = N - 1

  // コマ数が指定座標より多い場合。
  if (N > rest.length) {
    console.log(0)
    return
  }

  var list = []
  for(var i = 0; i < rest.length - 1; ++i) {
    var dist = rest[i + 1] - rest[i]
    list.push(dist)
  }

  list.sort((a, b) => a - b)
  list = list.slice(0, list.length - DIV)

  var ans = list.reduce((prev, current) => prev += current)
  console.log(ans)  
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));