CodeEff/ECCO huggingface dataset:
# Original solution
n,m = list(map(int,input().split()))
lst = [int(i) for i in input().split()]
lst.sort()
dst = []

if n>=m:
    print((0))
    exit()

for i in range(1,m):
    dst.append(lst[i]-lst[i-1])
dst.sort()
if n==1:
    ans = sum(dst)
else:
    ans = sum(dst[:-n+1])
print(ans)

# Optimized solution
n,m = list(map(int,input().split()))
lst = list(map(int,input().split()))
lst.sort()
dst = []
for i in range(1,m):
    dst.append(lst[i] - lst[i-1])
dst.sort()
if n >= m:
    print((0))
elif n==1:
    print((sum(dst)))
else:
    print((sum(dst[:-n+1])))
# Original solution
from itertools import combinations
import bisect
import copy

def move(positions, tmp_X, N, tmp_ans):
  min_dif = float('inf')
  min_idx = None
  min_x = None
  for x in tmp_X:
    idx = bisect.bisect_left(positions,x)
    if idx == N:
      tmp_dif = abs(x-positions[idx-1])
      tmp_idx = idx -1
    elif idx == 0:
      tmp_dif = abs(x-positions[idx])
      tmp_idx = idx
    else:
      dif1, dif2 = abs(x-positions[idx-1]), abs(x-positions[idx])
      if dif1 >= dif2:
        tmp_dif = dif2
        tmp_idx = idx
      else:
        tmp_dif = dif1
        tmp_idx = idx - 1

    if min_dif > tmp_dif:
      min_dif = tmp_dif
      min_idx = tmp_idx
      min_x = x
  
  del positions[min_idx]
  idx = bisect.bisect_left(positions, min_x)
  positions.insert(idx, min_x)

  tmp_X.remove(min_x)
  return tmp_ans + min_dif

N,M = list(map(int,input().split()))
X = list(map(int,input().split()))

if N >= M:
  print((0))
  exit()

ans = float('inf')
for cmb in combinations(X,N):
  tmp_ans = 0
  tmp_X = copy.deepcopy(X)
  positions = sorted(list(cmb))
  for position in positions: tmp_X.remove(position)
  
  while len(tmp_X) > 0:
    tmp_ans = move(positions, tmp_X, N, tmp_ans)
  ans = min(tmp_ans, ans)
print(ans)

# Optimized solution
N,M = list(map(int,input().split()))
if M == 1:
  print((0))
  exit()

X = sorted(list(map(int,input().split())))
difX = [0] + [X[i+1]-X[i] for i in range(M-1)]
difX.sort(reverse=True)
print((sum(difX)-sum(difX[:N-1])))
# Original solution
n,m = list(map(int, input().split()))
x = [int(i) for i in input().split()]

x_sort = sorted(x)
check = []
for i in range(len(x)-1):
    check.append(abs(x_sort[i+1] - x_sort[i]))

check_sorted = sorted(check)
ans = 0
if (m-n) >= 0:
    for i in check_sorted[0:m-n]:
        ans += i
    print(ans)
else:
    print((0))

# Optimized solution
n, m = list(map(int, input().split()))
X = [int(i) for i in input().split()]
X = sorted(X)
L = []
for i in range(1, m):
    L.append(X[i] - X[i - 1])
L = sorted(L)
if n >= m:
    print((0))
else:
    print((sum(L[0:m-n])))
# Original solution
import sys
N, M = list(map(int, input().split()))
X = [int(_) for _ in input().split()]
X.sort()
A = []
if N >= M:
    print((0))
    sys.exit()
else:
    for i in range(M - 1):
        A.append(X[i + 1] - X[i])
    for i in range(N - 1):
        A.remove(max(A))
sum = sum(A)
print(sum)

# Optimized solution
import sys
N, M = list(map(int, input().split()))
X = sorted(list(map(int,input().split())))
A = []
sum = 0
if N >= M:
    print((0))
    sys.exit()
else:
    for i in range(M - 1):
        A.append(X[i + 1] - X[i])
    A = sorted(A, reverse = True)
    for k in A[N - 1:]:
        sum += k
print(sum)
# Original solution
(n, m) = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
diff = []
for i in range(1, len(x)):
    diff.append(x[i] - x[i-1])
diff.sort(reverse=True)
sum = 0
for i in range(n - 1, len(diff)):
    sum += diff[i]
print(sum)

# Optimized solution
n, m = list(map(int, input().split()))
if n >= m:
    print((0))
    exit(0)

x = sorted(list(map(int, input().split())))
gaps = sorted([x[i] - x[i-1] for i in range(1, m)], reverse=True)
print((sum(gaps[n-1:])))
# Original solution
from itertools import combinations

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()

devide_num = min(N -1, M - 1)

devides = combinations(list(range(len(X))), devide_num)


mincost = X[-1] - X[0]
for devide in devides:
    previous = 0
    cost = 0
    for next_point in devide:
        cost += X[next_point] - X[previous]
        if next_point + 1 < M:
            previous = next_point + 1
        else:
            break
    # last
    cost += X[-1] - X[previous]

    mincost = min(cost, mincost)

print(mincost)






# Optimized solution
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()

diffs = [X[i+ 1] - X[i] for i in range(len(X) - 1)]
diffs.sort(reverse=True)

skip = N - 1
print((sum(diffs[skip:])))
# Original solution
from heapq import heappush, heappop


N, M = list(map(int, input().split()))
X = list(map(int, input().split()))

X.sort()

if N >= M:
    print((0))
    exit()

q1 = []

for i in range(M - 1):
    sec = X[i + 1] - X[i]
    heappush(q1, (-sec, i + 1))

q2 = []
for n in range(N - 1):
    sec, idx = heappop(q1)
    heappush(q2, idx)

heappush(q2, M)
cur = 0
ans = 0
for n in range(N):
    idx = heappop(q2)
    ans += X[idx - 1] - X[cur]
    cur = idx

print(ans)


# Optimized solution
from heapq import heappush, heappop


N, M = list(map(int, input().split()))
X = list(map(int, input().split()))

X.sort()

if N >= M:
    print((0))
    exit()

q1 = []

for i in range(M - 1):
    sec = X[i + 1] - X[i]
    heappush(q1, -sec)

ans = 0
for _ in range(N - 1):
    ans -= heappop(q1)

print((X[-1] - X[0] - ans))
# Original solution
n, m = list(map(int, input().split()))
li = list(map(int, input().split()))
 
li.sort()
move_cost = [li[i+1] - li[i] for i in range(m-1)]
move_cost.sort()
for i in range(n-1):
    if len(move_cost) == 0:
        break
    move_cost = move_cost[:-1]
 
print((sum(move_cost)))

# Optimized solution
n, m = list(map(int, input().split()))
li = list(map(int, input().split()))
 
li.sort()
move_cost = [li[i+1] - li[i] for i in range(m-1)]
move_cost.sort()
if n > 1:
    move_cost = move_cost[:-n+1]

print((sum(move_cost)))
# Original solution
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()

if n < m:
    x_distance = [abs(x[i + 1] - x[i]) for i in range(m - 1)]
    x_distance.sort()
    ans = 0
    for i in range (m - n):
        ans += x_distance[i]
    print(ans)
else:
    print((0))


# Optimized solution
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()

if n < m:
    x_distance = [x[i + 1] - x[i] for i in range(m - 1)]
    x_distance.sort()
    ans = 0
    for i in range (m - n):
        ans += x_distance[i]
    print(ans)
else:
    print((0))
# Original solution
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
if n < m:
    x_distance = [x[i + 1] - x[i] for i in range(m - 1)]
    x_distance.sort()
    print((sum(x_distance[:(m-n)])))
else:
    print((0))


# Optimized solution
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
x.sort()
if n < m:
    x_distance = [x2 - x1 for x1, x2 in zip(x, x[1:])]
    x_distance.sort()
    print((sum(x_distance[:(m-n)])))
else:
    print((0))
# Original solution
n, m = list(map(int, input().split()))
*x, = sorted(map(int, input().split()))

diff = []
for i in range(m-1):
    diff.append(abs(x[i]-x[i+1]))
partition = sorted(diff, reverse=True)[:(n-1)]

ans = 0
for _d in diff:
    if _d in partition:
        partition.remove(_d)
        continue

    ans += _d

print(ans)


# Optimized solution
n, m = list(map(int, input().split()))
*x, = sorted(map(int, input().split()))

diff = []
for i in range(m-1):
    diff.append(abs(x[i]-x[i+1]))
p = 0 if len(diff) < n else len(diff)-n+1
sec = sorted(diff)[:p]

print((sum(sec)))
# Original solution
N,M = list(map(int,input().split()))
X = sorted(list(map(int,input().split())))
D = sorted([X[n+1]-X[n] for n in range(M-1)])

if M<=N:
  print((0))
else:
  print((sum(D[:M-N])))

# Optimized solution
N,M = list(map(int,input().split()))
X = sorted(map(int,input().split()))
D = sorted(x2-x1 for x1,x2 in zip(X,X[1:]))[::-1]
print((sum(D[N-1:])))
# Original solution
import sys

N,M=list(map(int,input().split()))
X=list(map(int,input().split()))

if N>=M:
    print((0))
    sys.exit()

X.sort()

Y=[0]*(M-1)
for i in range(M-1):
    Y[i]=X[i+1]-X[i]

Y=sorted(Y)[:-(N-M)]
print((sum(Y)))

# Optimized solution
import sys

N,M=list(map(int,input().split()))
X=list(map(int,input().split()))

X.sort()

Y=[0]*(M-1)
for i in range(M-1):
    Y[i]=X[i+1]-X[i]

Y=sorted(Y)[:max(0,M-N)]
print((sum(Y)))
# Original solution
N, M = list(map(int, input().split()))
X = [int(i) for i in input().split()]

X.sort()

D = [X[i+1] - X[i] for i in range(M - 1)]

D.sort()

print((0 if M <= N else sum(D[:M-N])))


# Optimized solution
N, M = list(map(int, input().split()))
X = list(set([int(i) for i in input().split()]))

X.sort()

D = [X[i+1] - X[i] for i in range(M - 1)]

D.sort()

print((0 if M <= N else sum(D[:M-N])))
# Original solution
N, M = list(map(int, input().split()))
X = list(set([int(i) for i in input().split()]))

X.sort()

D = [X[i+1] - X[i] for i in range(M - 1)]

D.sort()

print((0 if M <= N else sum(D[:M-N])))


# Optimized solution
N, M = list(map(int, input().split()))
X = list(set(map(int, input().split())))

X.sort()

D = [X[i+1] - X[i] for i in range(M - 1)]

D.sort()

print((0 if M <= N else sum(D[:M-N])))
# Original solution
N,M = list(map(int, input().split()))
X = list(map(int,input().split()))
if N >= M:
  print((0))
else:
  X = sorted(X)
  list = []
  for i in range(M-1):
    list.append(X[i+1]-X[i])
    list = sorted(list)
    list1 = list[:M-N]
  print((sum(list1)))

# Optimized solution
N,M = list(map(int, input().split()))
X = list(map(int,input().split()))
if N >= M:
  print((0))
else:
  X = sorted(X)
  list = [X[i]-X[i-1] for i in range(1,M)]
  list = sorted(list)
  list1 = list[:M-N]
  print((sum(list1)))
# Original solution
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))

Y = sorted(X)
Y = list(map(lambda x,y:x-y, Y[1:],Y[:-1]))

for i in range(N-1):
	if Y != []:
		x = max(Y)
		Y.remove(x)
	else:
		break

print((sum(Y)))


# Optimized solution
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))

X.sort()
diffX = list(map(lambda x,y:x-y, X[1:], X[:-1]))
diffX.sort(reverse = True)

if N-1 >= len(diffX):
	print((0))
else:
	print((sum(diffX[N-1:])))
# Original solution
N,M = list(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)))


# Optimized solution
N,M = list(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)))
# Original solution
N,M = list(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)))


# Optimized solution
N,M = list(map(int,input().split()))
X = list(map(int,input().split()))
if N >= M :
    print((0))
    exit()
X.sort()
flag = [b-a for a,b in zip(X,X[1:])]
flag.sort()
print((sum(flag[:M-N:])))
# Original solution
import heapq
n,m = list(map(int, input().split(' ')))

# I am given n pieces
if n >= m:
	print(0)
else:
	xis = list(map(int, input().split()))
	xis.sort()


	distances = [v- u for u,v in zip(xis,xis[1:])]
	distances.sort(key = lambda x:-x)
	print(sum(distances[n-1:] or [0]))

# Optimized solution
import heapq
n,m = list(map(int, input().split(' ')))

xis = list(map(int, input().split()))
xis.sort()
distances = [v- u for u,v in zip(xis,xis[1:])]
distances.sort(key = lambda x:-x)
print(sum(distances[n-1:] or [0]))
# Original solution
def iread():
    return int(eval(input()))


def sread():
    return eval(input())


def aread_int():
    tmp = input().split()
    ret = [int(i) for i in tmp]
    return ret


def aread_str():
    return input().split()

if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    
    x = aread_int()
    x = sorted(x)
    x_dist = [0] * (m - 1)
    for i in range(m - 1) :
        x_dist[i] += abs(x[i] - x[i + 1])
    
    if n > m :
        print((0))
        exit()
    
    cost = sum(x_dist)
    for i in range(n - 1) :
        max_idx = x_dist.index(max(x_dist))
        cost -= x_dist[max_idx]
        # print(x_dist[max_idx])
        x_dist[max_idx] = 0

    print(cost)

# Optimized solution
def iread():
    return int(eval(input()))


def sread():
    return eval(input())


def aread_int():
    tmp = input().split()
    ret = [int(i) for i in tmp]
    return ret


def aread_str():
    return input().split()

if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    
    x = aread_int()
    x = sorted(x)
    x_dist = [0] * (m - 1)
    for i in range(m - 1) :
        x_dist[i] += abs(x[i] - x[i + 1])
    
    if n > m :
        print((0))
        exit()
    
    x_dist = sorted(x_dist)
    idx = len(x_dist) - 1
    cost = sum(x_dist)
    for i in range(n - 1) :
        cost -= x_dist[idx]
        x_dist[idx] = 0
        idx -= 1

    print(cost)
# Original solution
N, M = list(map(int,input().split()))
X = sorted(list(map(int,input().split())))

tmp = sorted([X[i+1] - X[i] for i in range(M-1)])
if(M <= N):
  print((0))
else:
  print((sum(tmp[:M-N])))

# Optimized solution
def ans():
  N, M = list(map(int,input().split()))
  X = sorted(list(map(int,input().split())))
  tmp = sorted([X[i+1] - X[i] for i in range(M-1)])
  if(M <= N):
    print((0))
  else:
    print((sum(tmp[:M-N])))
ans()
# Original solution
N, M = list(map(int,input().split()))
X = sorted(list(map(int,input().split())))
tmp = sorted([X[i+1]-X[i] for i in range(M-1)])
ans = sum(tmp[:M-N])
if(M <= N):
  ans = 0
print(ans)

# Optimized solution
N, M = list(map(int,input().split()))
X = sorted(map(int,input().split()))

X = sorted([X[i+1]-X[i] for i in range(M-1)])
ans = sum(X[:M-N])
if M <= N:
  ans = 0
print(ans)
# Original solution
N, M = list(map(int, input().split()))
X = sorted(map(int, input().split()))
diff = [0] * (M - 1)
for i in range(M - 1):
    diff[i] = X[i + 1] - X[i]
print((sum(sorted(diff)[: max(0, M - N)])))


# Optimized solution
N, M, *X = list(map(int, open(0).read().split()))

if N >= M:
    print((0))
    exit()

X.sort()
diff = []
for i in range(M - 1):
    diff.append(X[i + 1] - X[i])
diff.sort()
print((sum(diff[: M - N])))
# Original solution
N, M, *X = list(map(int, open(0).read().split()))

if N >= M:
    print((0))
    exit()

X.sort()
diff = []
for i in range(M - 1):
    diff.append(X[i + 1] - X[i])
diff.sort()
print((sum(diff[: M - N])))



# Optimized solution
from itertools import tee


def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return list(zip(a, b))


N, M, *X = list(map(int, open(0).read().split()))
if N >= M:
    print((0))
    exit()

X.sort()
diffs = [cur - prev for prev, cur in pairwise(X)]
diffs.sort()
print((sum(diffs[: M - N])))
# Original solution
N,M=list(map(int,input().split()))
X=list(map(int,input().split()))
if(N>=M):
    print((0))
else:
    X.sort()
    b=[]
    for i in range(M-1):
        b.append(X[i+1]-X[i])
    for i in range(N-1):
        b.remove(max(b))
    print((sum(b)))


# Optimized solution
N,M=list(map(int,input().split()))
X=list(map(int,input().split()))
if(N>=M):
    print((0))
else:
    X.sort()
    b=[]
    for i in range(M-1):
        b.append(X[i+1]-X[i])
    b.sort()
    for _ in range(N-1):
        b.pop()
    print((sum(b)))
# Original solution
N,M=list(map(int,input().split()))
X=list(map(int,input().split()))
if(N>=M):
    print((0))
else:
    X.sort()
    b=[]
    for i in range(M-1):
        b.append(X[i+1]-X[i])
    b.sort()
    for _ in range(N-1):
        b.pop()
    print((sum(b)))


# Optimized solution
n,m=list(map(int,input().split()))
l=sorted(list(map(int,input().split())))
if n>=m:
    print((0))
    exit()
s=l[-1]-l[0]
l=sorted([a-b for a,b in zip(l[1:],l)], reverse=True)
print((s-sum(l[:n-1])))
# Original solution
import itertools

N, M= (int(i) for i in input().split())
X = list(int(i) for i in input().split())
X.sort()

if(N >= M):
    print((0))
else:
    combination = list(itertools.combinations(list(range(M)),N-1))
    min = 2 * 100000
    for tmp_taple in combination:
        tmp_sum = 0
        from_index = 0
        for to_index in tmp_taple:
            tmp_sum += X[to_index] - X[from_index]
            from_index = to_index + 1
        if(from_index < M-1):
            tmp_sum += X[M-1] - X[from_index]
        if(min > tmp_sum):
            min = tmp_sum
    print(min)

# Optimized solution
N, M= (int(i) for i in input().split())
if (N<M):
    X = list(int(i) for i in input().split())
    X.sort()
    Y = [X[i] - X[i-1] for i in range(1, len(X))]
    Y.sort()
    print((sum(Y[0:M-N])))
else:
    print((0))


"""
N個のコマ：N-1個の閉経路が存在する
各座標の距離を求める(M-1個)
M：座標の数　N:駒の数
移動しなくても通っている座標の数: N
M - N
"""
# Original solution
N,M=list(map(int,input().split()))
X=sorted(list(map(int,input().split())))
d=[0]*(M-1)
for i in range(len(X)-1):
  d[i]=X[i+1]-X[i]
d=sorted(d)[::-1]
print((sum(d[N-1:])))

# Optimized solution
N,M=list(map(int,input().split()))
X=sorted(list(map(int,input().split())))
print((sum(sorted([X[i+1]-X[i] for i in range(M-1)])[::-1][N-1:])))
# Original solution
n,m = list(map(int, input().split()))
x = list(map(int, input().split()))

if n >= m:
    print((0))
    exit()
else:
    difference = []
    x.sort()
 
    for i in range(m-1):
        difference.append(x[i+1]-x[i])
 
    for i in range(n-1):
        difference.remove(max(difference))
 
    print((sum(difference)))


# Optimized solution
n,m = list(map(int, input().split()))
x = list(map(int, input().split()))

if n >= m:
    print((0))
    exit()
else:
    difference = []
    x.sort()
 
    for i in range(m-1):
        difference.append(x[i+1]-x[i])
 
    difference.sort()
 
    print((sum(difference[:m-n])))
# Original solution
N, M = list(map(int, input().split()))
X = sorted(list(map(int, input().split())))
d = [0] * (M - 1)
ans = 0

if N >= M:
    print(ans)
else:
    for i in range(M - 1):
        d[i] = abs(X[i + 1] - X[i])
    d.sort(reverse=True)
    b = d[:N - 1]
    for i in range(M - 1):
        if d[i] in b:
            b.remove(d[i])
        else:
            ans += d[i]
    print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
X = sorted(list(map(int, input().split())))
d = [0] * (M - 1)

if N >= M:
    print((0))
else:
    for i in range(M - 1):
        d[i] = abs(X[i + 1] - X[i])
    d.sort(reverse=True)
    print((sum(d[N - 1:])))
# Original solution
n,m =(int(i) for i in input().split())
x = list(int(i) for i in input().split())
x.sort()
sa = []
ans = 0
if m <= n:
  print('0')
  exit()
for i in range(m-1):
  sa.append(x[i+1]-x[i])
for i in range(n-1):
  tmp1 = max(sa)
  sa.remove(tmp1)

ans = sum(sa)
print(ans)

# Optimized solution
n,m =(int(i) for i in input().split())
x = list(int(i) for i in input().split())
x.sort()
sa = []
ans = 0
if m <= n:
  print('0')
  exit()
for i in range(m-1):
  sa.append(x[i+1]-x[i])
s2 = sorted(sa,reverse = True)
#print(s2)
for i in range(n-1,len(s2)):
  ans += s2[i]
print(ans)
# Original solution
import heapq

N, M = list(map(int, input().split()))
X = list(map(int, input().split()))

X.sort()
dist = [0]*(M-1)

for i in range(M-1):
    dist[i] = -(X[i+1] - X[i])
#print(dist)

heapq.heapify(dist)
for i in range(N-1):
    if len(dist) == 0:
        break
    heapq.heappop(dist)

ans = 0
if len(dist) != 0:
    ans = -sum(dist)
print(ans)


# Optimized solution
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))

X.sort()
dist = [0]*(M-1)

for i in range(M-1):
    dist[i] = X[i+1] - X[i]

dist.sort()
ans = 0
if N < M:
    for i in range((M-1)-(N-1)):
        ans += dist[i]

print(ans)
# Original solution
import sys
readline = sys.stdin.readline

def main():
    N, M = list(map(int, readline().rstrip().split()))
    X = list(map(int, readline().rstrip().split()))

    if N >= M:
        print((0))
        return

    X.sort()
    X = [abs(X[i+1]-X[i]) for i in range(M-1)]
    X.sort()
    ans = sum(X)
    for i in range(N-1):
        ans -= X[-i-1]
    
    print(ans)


if __name__ == '__main__':
    main()

# Optimized solution
import sys
readline = sys.stdin.readline

def main():
    N, M = list(map(int, readline().rstrip().split()))
    X = list(map(int, readline().rstrip().split()))

    if N >= M:
        print((0))
        return

    X.sort()
    X = [abs(X[i+1]-X[i]) for i in range(M-1)]
    X.sort(reverse=True)
    print((sum(X[N-1:])))


if __name__ == '__main__':
    main()
# Original solution
n,m=list(map(int,input().split()))
x=sorted([int(i) for i in input().split()])
xbet=sorted([abs(x[i+1]-x[i]) for i in range(m-1)],reverse=True)
y=sum(xbet)
if n>=m:
    print((0))
else:
    print((y-sum(xbet[:n-1])))


# Optimized solution
n,m=list(map(int,input().split()))
x=list(map(int,input().split()))
x.sort()
y=[x[i]-x[i-1] for i in range(1,m)]
y.sort()
print((0 if n>=m else sum(y[:(m-n)])))
# Original solution
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()

L = [0]*(M-1)
for i in range(M-1):
    L[i] = X[i+1]-X[i]
L.sort(reverse=True)

print((X[M-1]-X[0]-sum(L[:N-1])))

# Optimized solution
def main():
    N, M = list(map(int, input().split()))
    X = list(map(int, input().split()))
    X.sort()
    
    h = [0]*M
    for i in range(1, M):
        h[i] = X[i]-X[i-1]
    
    h.sort(reverse=True)
    print((X[M-1]-X[0]-sum(h[:(N-1)])))
main()
# Original solution
K, N = map(int, input().split())
MOD = 998244353

P = N+K
fact = [1]*(P+1)
rfact = [1]*(P+1)
for i in range(P):
    fact[i+1] = r = ((i+1) * fact[i]) % MOD
    rfact[i+1] = pow(r, MOD-2, MOD)

def comb(n, k):
    return fact[n] * rfact[k] * rfact[n-k] % MOD

pow2 = [1]*(P+1)
r = 1
for i in range(P):
    r = pow2[i+1] = (r * 2) % MOD

def calc(A):
    M = A//2
    r = 0
    if A % 2:
        p = K - 2*M + N - 2
        for m in range(max(0, 2*M+2-K), min(M, N-1)+1):
            r += pow2[m] * comb(M, m) * (comb(p, N-m) + comb(p-1, N-m-1)) % MOD
        if 2*M+2-K <= N <= M:
            r += pow2[N] * comb(M, N) % MOD
    else:
        p = K - 2*M + N - 1
        for m in range(max(0, 2*M+1-K), min(N, M)+1):
            r += pow2[m] * comb(M, m) * comb(p, N-m) % MOD
    return r % MOD
ans = []
for i in range(2, 2*K+1):
    if i <= K:
        ans.append(calc(i - 1))
    else:
        ans.append(calc(2*K - i + 1))
print(*ans, sep='\n')


# Optimized solution
K, N = map(int, input().split())
MOD = 998244353

P = N+K
fact = [1]*(P+1)
rfact = [1]*(P+1)
for i in range(P):
    fact[i+1] = r = ((i+1) * fact[i]) % MOD
    rfact[i+1] = pow(r, MOD-2, MOD)

def comb(n, k):
    return fact[n] * rfact[k] * rfact[n-k] % MOD

V = [1]*(P+1)
r = 1
for i in range(P):
    r = (r * 2) % MOD
    V[i+1] = r * rfact[i+1] % MOD

memo = {}
def calc(A):
    if A in memo:
        return memo[A]
    M = A//2
    r = 0
    if A % 2:
        p = K - 2*M + N - 2
        for m in range(max(0, 2*M+2-K), min(M, N-1)+1):
            r += V[m] * rfact[M-m] * (fact[p]*rfact[N-m] + fact[p-1]*rfact[N-m-1])*rfact[p-N+m] % MOD

        if 2*M+2-K <= N <= M:
            r += V[N] * rfact[M-N] % MOD
        r *= fact[M]
    else:
        p = K - 2*M + N - 1
        for m in range(max(0, 2*M+1-K), min(N, M)+1):
            r += V[m] * rfact[M-m] * rfact[N-m] * rfact[p-N+m] % MOD
        r *= fact[M] * fact[p]
    r = memo[A] = r % MOD
    return r
ans = []
for i in range(2, 2*K+1):
    if i <= K:
        ans.append(calc(i - 1))
    else:
        ans.append(calc(2*K - i + 1))
print(*ans, sep='\n')