#include <bits/stdc++.h>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	long x[M], diff[M-1];
	for(int i = 0; i < M; i++) {
		cin >> x[i];
	}
	sort(x, x+M);
	
	for(int i = 0; i < M-1; i++) {
		diff[i] = x[i+1] - x[i];
	}
	sort(diff, diff+M-1);
	long sum = 0;
	for(int i = 0; i < M-N; i++) {
		sum += diff[i];
	}
	cout << sum << endl;
	return 0;
}