def main():

    n, m = list(map(int, input().split()))

    t = list(map(int, input().split()))

    if n >= m:

        return 0

    t.sort()

    x = [[t[i], t[i+1] - t[i]] for i in range(m-1)]

    x.append([t[m-1], 0])

    x.sort(key=lambda a: a[1], reverse=True)

    sum_dis = t[m-1] - t[0]

    skip_dis = sum([x[i][1] for i in range(n - 1)])

    return sum_dis - skip_dis





print((main()))
def main():

    N, M = list(map(int, input().split()))

    t = [int(i) for i in input().split()]

    t.sort()



    if N >= M:

        return 0



    x = [j-i for i, j in zip(t, t[1:])]

    x.sort(reverse=True)

    return (t[-1] - t[0]) - sum([x[i] for i in range(N - 1)])





print((main()))

def main():
    n, m = list(map(int, input().split()))
    t = list(map(int, input().split()))
    if n >= m:
        return 0
    t.sort()
    x = [[t[i], t[i + 1] - t[i]] for i in range(m - 1)]
    x.append([t[m - 1], 0])
    x.sort(key=lambda a: a[1], reverse=True)
    sum_dis = t[m - 1] - t[0]
    skip_dis = sum([x[i][1] for i in range(n - 1)])
    return sum_dis - skip_dis


print((main()))

def main():
    N, M = list(map(int, input().split()))
    t = [int(i) for i in input().split()]
    t.sort()
    if N >= M:
        return 0
    x = [j - i for i, j in zip(t, t[1:])]
    x.sort(reverse=True)
    return (t[-1] - t[0]) - sum([x[i] for i in range(N - 1)])


print((main()))

-    n, m = list(map(int, input().split())) -    t = list(map(int, input().split())) -    if n >= m: +    N, M = list(map(int, input().split())) +    t = [int(i) for i in input().split()] +    t.sort() +    if N >= M: -    t.sort() -    x = [[t[i], t[i + 1] - t[i]] for i in range(m - 1)] -    x.append([t[m - 1], 0]) -    x.sort(key=lambda a: a[1], reverse=True) -    sum_dis = t[m - 1] - t[0] -    skip_dis = sum([x[i][1] for i in range(n - 1)]) -    return sum_dis - skip_dis +    x = [j - i for i, j in zip(t, t[1:])] +    x.sort(reverse=True) +    return (t[-1] - t[0]) - sum([x[i] for i in range(N - 1)])