def main():

    N, M = (int(i) for i in input().split())

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

    if N >= M: 

        print((0))

    elif N < M: 

        X.sort()

        diff = [[0,0] for _ in range(M-1)]

        for i in range(M-1):

            diff[i] = [X[i+1] - X[i],i]

        diff.sort(reverse=True)

        diff = diff[:N-1]

        diff.sort(key=lambda p:p[1])



        ans = 0

        cnt = 0

        for i in range(N-1):

            ans += X[diff[i][1]] - X[cnt]

            cnt = diff[i][1] + 1

        ans += X[-1] - X[cnt]

        print(ans)

if __name__ == "__main__":

    main()
def main():

    N, M = (int(i) for i in input().split())

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

    if N >= M: 

        print((0))

    elif N < M: 

        X.sort()

        diff = [0 for _ in range(M-1)]

        for i in range(M-1):

            diff[i] = X[i+1] - X[i]

        diff.sort(reverse=True)

        

        ans = X[-1] - X[0]

        for i in range(N-1):

            ans -= diff[i]

        print(ans)

if __name__ == "__main__":

    main()
def main():
    N, M = (int(i) for i in input().split())
    X = [int(i) for i in input().split()]
    if N >= M:
        print((0))
    elif N < M:
        X.sort()
        diff = [[0, 0] for _ in range(M - 1)]
        for i in range(M - 1):
            diff[i] = [X[i + 1] - X[i], i]
        diff.sort(reverse=True)
        diff = diff[: N - 1]
        diff.sort(key=lambda p: p[1])
        ans = 0
        cnt = 0
        for i in range(N - 1):
            ans += X[diff[i][1]] - X[cnt]
            cnt = diff[i][1] + 1
        ans += X[-1] - X[cnt]
        print(ans)


if __name__ == "__main__":
    main()

def main():
    N, M = (int(i) for i in input().split())
    X = [int(i) for i in input().split()]
    if N >= M:
        print((0))
    elif N < M:
        X.sort()
        diff = [0 for _ in range(M - 1)]
        for i in range(M - 1):
            diff[i] = X[i + 1] - X[i]
        diff.sort(reverse=True)
        ans = X[-1] - X[0]
        for i in range(N - 1):
            ans -= diff[i]
        print(ans)


if __name__ == "__main__":
    main()

-        diff = [[0, 0] for _ in range(M - 1)] +        diff = [0 for _ in range(M - 1)] -            diff[i] = [X[i + 1] - X[i], i] +            diff[i] = X[i + 1] - X[i] -        diff = diff[: N - 1] -        diff.sort(key=lambda p: p[1]) -        ans = 0 -        cnt = 0 +        ans = X[-1] - X[0] -            ans += X[diff[i][1]] - X[cnt] -            cnt = diff[i][1] + 1 -        ans += X[-1] - X[cnt] +            ans -= diff[i]