Buggy python submission (verdict: Runtime Error):
##N Mの入力                                                                                                                                                                                                 
N,M = [int(x) for x in input().split()]
##地点の保存                                                                                                                                                                                                
x = [int(num) for num in input().split()]
##地点のソート                                                                                                                                                                                              
x = sorted(x)
##それぞれの幅の決定                                                                                                                                                                                        
dis = [x[i+1]-x[i] for i in range(M-1)]
##幅の長さのソート                                                                                                                                                                                          
dis = sorted(dis)
##答えの算出                                                                                                                                                                                                
dis_top = 0
for i in range(1,N):
    dis_top = dis_top + dis[(M-1)-i]
##答えの出力                                                                                                                                                                                                
ans = sum(dis) - dis_top
print(ans)



Fixed submission:
##N Mの入力                                                                                                                                                                                                 
N,M = [int(x) for x in input().split()]
##地点の保存                                                                                                                                                                                                
x = [int(num) for num in input().split()]
##地点のソート                                                                                                                                                                                              
x = sorted(x)
##それぞれの幅の決定                                                                                                                                                                                        
dis = [x[i+1]-x[i] for i in range(M-1)]
##幅の長さのソート                                                                                                                                                                                          
dis = sorted(dis)
##答えの算出                                                                                                                                                                                                
dis_top = 0
for i in range(1,N):
    if((M-1)-i < 0):
        break;
    dis_top = dis_top + dis[(M-1)-i]
##答えの出力                                                                                                                                                                                                
ans = sum(dis) - dis_top
print(ans)