import numpy as np





def solve(string):

    n, m, *x = list(map(int, string.split()))

    x = sorted(np.diff(sorted(x)))

    return str(sum(x)) if n == 1 else str(sum(x[:-n + 1]))





if __name__ == '__main__':

    print((solve("\n".join([eval(input()), eval(input())]))))

import numpy as np





def solve(string):

    n, m, *x = list(map(int, string.split()))

    x = sorted(np.diff(sorted(x)), reverse=True)

    return str(sum(x[n - 1:]))





if __name__ == '__main__':

    print((solve("\n".join([eval(input()), eval(input())]))))

import numpy as np


def solve(string):
    n, m, *x = list(map(int, string.split()))
    x = sorted(np.diff(sorted(x)))
    return str(sum(x)) if n == 1 else str(sum(x[: -n + 1]))


if __name__ == "__main__":
    print((solve("\n".join([eval(input()), eval(input())]))))

import numpy as np


def solve(string):
    n, m, *x = list(map(int, string.split()))
    x = sorted(np.diff(sorted(x)), reverse=True)
    return str(sum(x[n - 1 :]))


if __name__ == "__main__":
    print((solve("\n".join([eval(input()), eval(input())]))))

-    x = sorted(np.diff(sorted(x))) -    return str(sum(x)) if n == 1 else str(sum(x[: -n + 1])) +    x = sorted(np.diff(sorted(x)), reverse=True) +    return str(sum(x[n - 1 :]))