Buggy python submission (verdict: Runtime Error):
NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

Xin= input().split(" ")


Xls = []
tousa = []
for i in range(0,M):
    Xls.append(int(Xin[i]))

Xls.sort()

if M != 1:
    for i in range(0,M-1):
        tousa.append(abs(Xls[i+1] - Xls[i]))




tousa.sort()

if N>M:
    w = M-1
else:
    w = N
for i in range(0,w):
    tousa.pop()

ret = 0

for i in tousa:
    ret = i + ret

print(ret)


Fixed submission:
NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

Xin= input().split(" ")


Xls = []
tousa = []
for i in range(0,M):
    Xls.append(int(Xin[i]))

Xls.sort()

if M != 1:
    for i in range(0,M-1):
        tousa.append(abs(Xls[i+1] - Xls[i]))




tousa.sort()


if N<M:
    for i in range(0,N-1):
        tousa.pop()
else:
    print(0)
    exit()
ret = 0

for i in tousa:
    ret = i + ret

print(ret)

Buggy python submission (verdict: Runtime Error):
NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

Xin= input().split(" ")


Xls = []
tousa = []
for i in range(0,M):
    Xls.append(int(Xin[i]))

Xls.sort()

if M != 1:
    for i in range(0,M-1):
        tousa.append(abs(Xls[i+1] - Xls[i]))

if M == 1:
    print(0)
    exit()

tousa.sort()
if N != 1:
    for i in range(0,N-1):
        tousa.pop()

ret = 0

for i in tousa:
    ret = i + ret

print(ret)


Fixed submission:
NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

Xin= input().split(" ")


Xls = []
tousa = []
for i in range(0,M):
    Xls.append(int(Xin[i]))

Xls.sort()

if M != 1:
    for i in range(0,M-1):
        tousa.append(abs(Xls[i+1] - Xls[i]))




tousa.sort()


if N<M:
    for i in range(0,N-1):
        tousa.pop()
else:
    print(0)
    exit()
ret = 0

for i in tousa:
    ret = i + ret

print(ret)

Buggy python submission (verdict: Runtime Error):
NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

Xin= input().split(" ")


Xls = []
tousa = []
for i in range(0,M):
    Xls.append(int(Xin[i]))

Xls.sort()

if M != 1:
    for i in range(0,M-1):
        tousa.append(abs(Xls[i+1] - Xls[i]))

if M == 1:
    print(0)
    exit()

tousa.sort()
for i in range(0,N-1):
    tousa.pop()

ret = 0

for i in tousa:
    ret = i + ret

print(ret)


Fixed submission:
NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

Xin= input().split(" ")


Xls = []
tousa = []
for i in range(0,M):
    Xls.append(int(Xin[i]))

Xls.sort()

if M != 1:
    for i in range(0,M-1):
        tousa.append(abs(Xls[i+1] - Xls[i]))




tousa.sort()


if N<M:
    for i in range(0,N-1):
        tousa.pop()
else:
    print(0)
    exit()
ret = 0

for i in tousa:
    ret = i + ret

print(ret)

Buggy python submission (verdict: Runtime Error):
NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

Xin= input().split(" ")


Xls = []
tousa = []
for i in range(0,M):
    Xls.append(int(Xin[i]))

Xls.sort()

for i in range(0,M-1):
    tousa.append(abs(Xls[i+1] - Xls[i]))

if M == 1:
    print(0)
    exit()

tousa.sort()
for i in range(0,N-1):
    tousa.pop()

ret = 0

for i in tousa:
    ret = i + ret

print(ret)


Fixed submission:
NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

Xin= input().split(" ")


Xls = []
tousa = []
for i in range(0,M):
    Xls.append(int(Xin[i]))

Xls.sort()

if M != 1:
    for i in range(0,M-1):
        tousa.append(abs(Xls[i+1] - Xls[i]))




tousa.sort()


if N<M:
    for i in range(0,N-1):
        tousa.pop()
else:
    print(0)
    exit()
ret = 0

for i in tousa:
    ret = i + ret

print(ret)

Buggy python submission (verdict: Runtime Error):
NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

Xin= input().split(" ")


Xls = []
tousa = []
for i in range(0,M):
    Xls.append(int(Xin[i]))

Xls.sort()

for i in range(0,M-1):
    tousa.append(abs(Xls[i+1] - Xls[i]))

if M == 1:
    print(0)

tousa.sort()
for i in range(0,N-1):
    tousa.pop()

ret = 0

for i in tousa:
    ret = i + ret

print(ret)


Fixed submission:
NM = input().split(" ")
N = int(NM[0])
M = int(NM[1])

Xin= input().split(" ")


Xls = []
tousa = []
for i in range(0,M):
    Xls.append(int(Xin[i]))

Xls.sort()

if M != 1:
    for i in range(0,M-1):
        tousa.append(abs(Xls[i+1] - Xls[i]))




tousa.sort()


if N<M:
    for i in range(0,N-1):
        tousa.pop()
else:
    print(0)
    exit()
ret = 0

for i in tousa:
    ret = i + ret

print(ret)