# ABC117C - Streamline

def main():

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

    lst = sorted(list(map(int, input().rstrip().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 = list(map(int, input().rstrip().split()))

    lst = sorted(set(map(int, input().rstrip().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 = list(map(int, input().rstrip().split()))
    lst = sorted(list(map(int, input().rstrip().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 = list(map(int, input().rstrip().split()))
    lst = sorted(set(map(int, input().rstrip().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()

-    lst = sorted(list(map(int, input().rstrip().split()))) +    lst = sorted(set(map(int, input().rstrip().split())))