import sys

import os





def main():

    if os.getenv("LOCAL"):

        sys.stdin = open("input.txt", "r")



    N, M = list(map(int, sys.stdin.readline().split()))

    lines = list(map(int, sys.stdin.readline().split()))

    lines.sort()



    cost = {}

    for i in range(len(lines) - 1):

        tmp = lines[i + 1] - lines[i]

        cost[i] = tmp



    sortedCost = sorted(list(cost.items()), key=lambda x: x[1], reverse=True)

    ret = 0

    for i, c in sortedCost[N - 1:]:

        ret += c



    print(ret)





if __name__ == '__main__':

    main()

import sys, os, math, bisect, itertools, collections, heapq, queue

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall

from decimal import Decimal

from collections import defaultdict, deque



# import fractions



sys.setrecursionlimit(10000000)



ii = lambda: int(sys.stdin.buffer.readline().rstrip())

il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))

iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]



iss = lambda: sys.stdin.buffer.readline().decode().rstrip()

sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))

isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]



lcm = lambda x, y: (x * y) // math.gcd(x, y)

# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)



MOD = 10 ** 9 + 7

MAX = float('inf')





def main():

    if os.getenv("LOCAL"):

        sys.stdin = open("input.txt", "r")



    N, M = il()

    X = sorted(il())



    diff = []

    for n in range(M - 1):

        diff.append(abs(X[n] - X[n + 1]))

    diff = sorted(diff, reverse=True)

    ret = sum(diff[N-1:])

    print(ret)





if __name__ == '__main__':

    main()

import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")
    N, M = list(map(int, sys.stdin.readline().split()))
    lines = list(map(int, sys.stdin.readline().split()))
    lines.sort()
    cost = {}
    for i in range(len(lines) - 1):
        tmp = lines[i + 1] - lines[i]
        cost[i] = tmp
    sortedCost = sorted(list(cost.items()), key=lambda x: x[1], reverse=True)
    ret = 0
    for i, c in sortedCost[N - 1 :]:
        ret += c
    print(ret)


if __name__ == "__main__":
    main()

import sys, os, math, bisect, itertools, collections, heapq, queue

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

# import fractions
sys.setrecursionlimit(10000000)
ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]
lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)
MOD = 10**9 + 7
MAX = float("inf")


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")
    N, M = il()
    X = sorted(il())
    diff = []
    for n in range(M - 1):
        diff.append(abs(X[n] - X[n + 1]))
    diff = sorted(diff, reverse=True)
    ret = sum(diff[N - 1 :])
    print(ret)


if __name__ == "__main__":
    main()

-import sys -import os +import sys, os, math, bisect, itertools, collections, heapq, queue + +# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall +from decimal import Decimal +from collections import defaultdict, deque + +# import fractions +sys.setrecursionlimit(10000000) +ii = lambda: int(sys.stdin.buffer.readline().rstrip()) +il = lambda: list(map(int, sys.stdin.buffer.readline().split())) +fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) +iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] +iss = lambda: sys.stdin.buffer.readline().decode().rstrip() +sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) +isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] +lcm = lambda x, y: (x * y) // math.gcd(x, y) +# lcm = lambda x, y: (x * y) // fractions.gcd(x, y) +MOD = 10**9 + 7 +MAX = float("inf") -    N, M = list(map(int, sys.stdin.readline().split())) -    lines = list(map(int, sys.stdin.readline().split())) -    lines.sort() -    cost = {} -    for i in range(len(lines) - 1): -        tmp = lines[i + 1] - lines[i] -        cost[i] = tmp -    sortedCost = sorted(list(cost.items()), key=lambda x: x[1], reverse=True) -    ret = 0 -    for i, c in sortedCost[N - 1 :]: -        ret += c +    N, M = il() +    X = sorted(il()) +    diff = [] +    for n in range(M - 1): +        diff.append(abs(X[n] - X[n + 1])) +    diff = sorted(diff, reverse=True) +    ret = sum(diff[N - 1 :])