# ABC117C - Streamline

def main():

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

    lst = sorted(set(map(int, input().split())))

    dis = []

    for i, j in zip(lst, lst[1:]):

        dis += [j - i]

    print((sum(sorted(dis, reverse=True)[n - 1 :])))





if __name__ == "__main__":

    main()

# ABC117C - Streamline

def main():

    N, M, *X = list(map(int, open(0).read().split()))

    X = sorted(set(X))

    dist = []

    for i, j in zip(X, X[1:]):

        dist.append(j - i)

    dist.sort(reverse=1)

    ans = sum(dist[N - 1 :])

    print(ans)





if __name__ == "__main__":

    main()
# ABC117C - Streamline
def main():
    n, m = list(map(int, input().split()))
    lst = sorted(set(map(int, input().split())))
    dis = []
    for i, j in zip(lst, lst[1:]):
        dis += [j - i]
    print((sum(sorted(dis, reverse=True)[n - 1 :])))


if __name__ == "__main__":
    main()

# ABC117C - Streamline
def main():
    N, M, *X = list(map(int, open(0).read().split()))
    X = sorted(set(X))
    dist = []
    for i, j in zip(X, X[1:]):
        dist.append(j - i)
    dist.sort(reverse=1)
    ans = sum(dist[N - 1 :])
    print(ans)


if __name__ == "__main__":
    main()

-    n, m = list(map(int, input().split())) -    lst = sorted(set(map(int, input().split()))) -    dis = [] -    for i, j in zip(lst, lst[1:]): -        dis += [j - i] -    print((sum(sorted(dis, reverse=True)[n - 1 :]))) +    N, M, *X = list(map(int, open(0).read().split())) +    X = sorted(set(X)) +    dist = [] +    for i, j in zip(X, X[1:]): +        dist.append(j - i) +    dist.sort(reverse=1) +    ans = sum(dist[N - 1 :]) +    print(ans)