Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    X.sort()
    x_next = X[0]
    flag = [X[_] - X[_-1] for _ in range(1,M)]
    for lp in range(N-1):
        ff = flag.index(max(flag))
        flag.pop(ff)
    print(sum(flag))


Fixed submission:
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    X.sort()
    x_next = X[0]
    flag = [X[_] - X[_-1] for _ in range(1,M)]
    flag.sort()
    flag = flag[:M-N:]
    print(sum(flag))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    flag = []
    X.sort()
    x_next = X[0]
    for _ in X:
        flag.append(_ - x_next)
        x_next = _
    for lp in range(N-1):
        ff = flag.index(max(flag))
        flag.pop(ff)
    print(sum(flag))

Fixed submission:
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    X.sort()
    x_next = X[0]
    flag = [X[_] - X[_-1] for _ in range(1,M)]
    flag.sort()
    flag = flag[:M-N:]
    print(sum(flag))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    flag = []
    X.sort()
    for _ in range(1,M):
        flag.append(X[_] - X[_-1])
    for lp in range(N-1):
        flag.pop(flag.index(max(flag)))
    print(sum(flag))

Fixed submission:
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    X.sort()
    x_next = X[0]
    flag = [X[_] - X[_-1] for _ in range(1,M)]
    flag.sort()
    flag = flag[:M-N:]
    print(sum(flag))

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    flag = [0 for fl in range(M-1)]
    X.sort()
    for _ in range(1,M):        
        flag[_-1] += X[_] - X[_-1]
    for lp in range(N-1):
        ff = flag.index(max(flag))
        flag.pop(ff)
    print(sum(flag))

Fixed submission:
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    X.sort()
    x_next = X[0]
    flag = [X[_] - X[_-1] for _ in range(1,M)]
    flag.sort()
    flag = flag[:M-N:]
    print(sum(flag))

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    flag = [0 for fl in range(M)]
    X.sort()
    for _ in range(1,M+1):
        flag[_] += X[_] - X[_-1]
    for lp in range(len(flag)):
      	ff = flag.index(max(flag))
        flag.pop(ff)
        print(sum(flag))


Fixed submission:
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    X.sort()
    x_next = X[0]
    flag = [X[_] - X[_-1] for _ in range(1,M)]
    flag.sort()
    flag = flag[:M-N:]
    print(sum(flag))

Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    flag = [0 for fl in range(M)]
    X.sort()
    for _ in range(1,M):
        flag[_] += X[_] - X[_-1]
   for lp in range(N-1):
        flag.pop(flag.index(max(flag)))
        print(sum(flag))


Fixed submission:
N,M = map(int,input().split())
X = list(map(int,input().split()))
if N > M :
    print(0)
else:
    X.sort()
    x_next = X[0]
    flag = [X[_] - X[_-1] for _ in range(1,M)]
    flag.sort()
    flag = flag[:M-N:]
    print(sum(flag))