You are given a sorted array $a_1, a_2, \dots, a_n$ (for each index $i > 1$ condition $a_i \ge a_{i-1}$ holds) and an integer $k$.

You are asked to divide this array into $k$ non-empty consecutive subarrays. Every element in the array should be included in exactly one subarray. 

Let $max(i)$ be equal to the maximum in the $i$-th subarray, and $min(i)$ be equal to the minimum in the $i$-th subarray. The cost of division is equal to $\sum\limits_{i=1}^{k} (max(i) - min(i))$. For example, if $a = [2, 4, 5, 5, 8, 11, 19]$ and we divide it into $3$ subarrays in the following way: $[2, 4], [5, 5], [8, 11, 19]$, then the cost of division is equal to $(4 - 2) + (5 - 5) + (19 - 8) = 13$.

Calculate the minimum cost you can obtain by dividing the array $a$ into $k$ non-empty consecutive subarrays. 


-----Input-----

The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 3 \cdot 10^5$).

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($ 1 \le a_i \le 10^9$, $a_i \ge a_{i-1}$). 


-----Output-----

Print the minimum cost you can obtain by dividing the array $a$ into $k$ nonempty consecutive subarrays. 


-----Examples-----
Input
6 3
4 8 15 16 23 42

Output
12

Input
4 4
1 3 3 7

Output
0

Input
8 1
1 1 2 3 5 8 13 21

Output
20



-----Note-----

In the first test we can divide array $a$ in the following way: $[4, 8, 15, 16], [23], [42]$.

Difficulty: MEDIUM
Tags: Sorting

Greedy algorithms
Skill types: Sorting

Greedy algorithms
Expected Time Complexity: O(NLOG(N))

Starter code:

Solutions:
(n, k) = map(int, input().split())
lis = list(map(int, input().split()))
an = []
for i in range(1, n):
	an.append(lis[i] - lis[i - 1])
ans = sorted(range(len(an)), key=lambda k: an[k], reverse=True)
for i in range(k - 1):
	an[ans[i]] = 0
print(sum(an))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n - 2, -1, -1):
	a[i] += a[i + 1]
sm = a[0]
a = sorted(a[1:])
a = a[::-1]
print(sm + sum(a[:k - 1]))


import sys
(n, k) = list(map(int, sys.stdin.readline().split()))
a = list(map(int, sys.stdin.readline().split()))
d = []
for i in range(1, n):
	d.append(a[i] - a[i - 1])
d.sort()
print(sum(d[:n - k]))


(n, k) = map(int, input().split())
List = list(map(int, input().split()))
List2 = [0]
for i in range(1, n):
	List2.append(List[i] - List[i - 1])
List2.sort()
out = 0
for i in range(n - k + 1):
	out += List2[i]
print(out)


(x, y) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(1, x):
	b.append(a[i] - a[i - 1])
b.sort()
c = a[x - 1] - a[0]
d = len(b) - 1
for i in range(y - 1):
	c -= b[d - i]
print(c)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(1, n):
	b.append((a[i] - a[i - 1], i))
b.sort(reverse=True)
c = [0, n]
for i in range(k - 1):
	c.append(b[i][1])
c.sort()
ans = 0
for i in range(k):
	ans += a[c[i + 1] - 1] - a[c[i]]
print(ans)


(n, k) = input().split()
n = int(n)
k = int(k) - 1
a = []
a += input().split()
a = list(map(int, a))
maxraz = a[n - 1] - a[0]
d = []
for i in range(n - 1):
	d.append(a[i + 1] - a[i])
d = list(map(int, d))
e = []
e = sorted(d)
summ = 0
for i in range(n - k - 1, n - 1):
	summ += e[i]
print(maxraz - summ)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = a[-1] - a[0]
l = []
for i in range(n - 1):
	l.append(a[i] - a[i + 1])
l.sort()
for j in range(k - 1):
	ans += l[j]
print(ans)


(n, k) = list(map(int, input().split()))
arr = [int(x) for x in input().split()]
diff = [0] * (n - 1)
p = arr[-1] - arr[0]
for i in range(n - 1):
	diff[i] = arr[i + 1] - arr[i]
diff.sort(reverse=True)
print(p - sum(diff[:k - 1]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = list()
if n > 1:
	for i in range(1, n):
		d.append(a[i] - a[i - 1])
d.sort(reverse=True)
s = 0
for i in range(k - 1):
	s = s + d[i]
print(a[n - 1] - a[0] - s)


(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
point = [0] * (n + 1)
mask = []
for i in range(1, n):
	mask.append([l[i] - l[i - 1], i - 1])
mask.sort(reverse=True)
for i in range(k - 1):
	point[mask[i][1]] = 1
ans = 0
last = 0
for i in range(n):
	if i == n - 1 or point[i]:
		ans += l[i] - l[last]
		last = i + 1
print(ans)


(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
sum1 = 0
br = []
for i in range(1, n):
	x = ar[i] - ar[i - 1]
	sum1 += x
	br.append(x)
br.sort()
if k == 1:
	print(sum1)
else:
	print(sum1 - sum(br[-k + 1:]))


import sys
input = sys.stdin.readline
(n, k) = list(map(int, input().split()))
A = [int(i) for i in input().split()]
B = []
for i in range(1, n):
	B.append(A[i] - A[i - 1])
B.sort()
print(sum(B[:n - k]))


(n, m) = map(int, input().split())
ls = list(map(int, input().split()))
ls2 = []
for i in range(1, n):
	ls2.append(ls[i - 1] - ls[i])
ans = ls[n - 1] - ls[0]
ls2.sort()
for i in range(m - 1):
	ans += ls2[i]
print(ans)


(n, k) = map(int, input().split())
numbers = list(map(int, input().split()))
differences = [0] * (n - 1)
for i in range(n - 1):
	differences[i] = numbers[i + 1] - numbers[i]
differences.sort()
(i, m, s) = (0, n, 0)
while m > k:
	s += differences[i]
	i += 1
	m -= 1
print(s)


(N, K) = map(int, input().split())
A = [int(a) for a in input().split()]
D = sorted([A[i + 1] - A[i] for i in range(N - 1)])
print(A[-1] - A[0] - (sum(D[-K + 1:]) if K - 1 else 0))


from collections import Counter, defaultdict, deque
from math import factorial as fact

def primes(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors

def issubseq(s, t):
	if len(t) > len(s):
		return False
	lt = len(t)
	p = 0
	for el in s:
		if el == t[p]:
			p += 1
		if p == lt:
			return True
	return False
(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
ans = a[-1] - a[0]
d = []
for i in range(n - 1):
	d.append(a[i] - a[i + 1])
d.sort()
for i in range(k - 1):
	ans += d[i]
print(ans)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
if n == k:
	print(0)
else:
	b = [0] * (n - 1)
	for i in range(0, n - 1):
		b[i] = a[i + 1] - a[i]
	b = sorted(b)
	s = 0
	for j in range(0, n - k):
		s = s + b[j]
	print(s)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
D = []
for i in range(n - 1):
	d = A[i] - A[i + 1]
	D.append(d)
D.sort()
ans = -A[0] + A[-1]
for i in range(k - 1):
	ans += D[i]
print(ans)


(n, k) = map(int, input().split())
arr = [int(i) for i in input().split()]
lst = []
ans = arr[n - 1] - arr[0]
for i in range(1, n):
	lst.append(arr[i - 1] - arr[i])
lst.sort()
for i in range(k - 1):
	ans += lst[i]
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
d = []
for i in range(1, n):
	d.append(l[i - 1] - l[i])
d.sort()
s = l[n - 1] - l[0]
for i in range(k - 1):
	s = s + d[i]
print(s)


def __starting_point():
	s = input().rstrip().split()
	N = int(s[0])
	K = int(s[1])
	a = list(map(int, list(input().rstrip().split())))
	diff = []
	for i in range(1, N):
		diff.append([i, a[i] - a[i - 1]])
	diff = sorted(diff, key=lambda x: -x[1])
	res = max(a) - min(a)
	k = 0
	while k < K - 1 and k < len(diff):
		res -= diff[k][1]
		k += 1
	print(res)
__starting_point()


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
if k == n:
	print(0)
elif k == 1:
	print(max(a) - min(a))
else:
	b = [0] * (n - 1)
	for i in range(1, n):
		b[i - 1] = (a[i] - a[i - 1], i - 1)
	b = sorted(b)[::-1]
	if k == n - 1:
		print(b[-1][0])
	else:
		s = 0
		bps = []
		for i in range(k - 1):
			bp = b[i][1]
			bps.append(bp + 1)
		bps = sorted(bps)
		bps.append(n)
		st = 0
		for i in bps:
			s += a[i - 1] - a[st]
			st = i
		print(s)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
print(sum(sorted([a[i + 1] - a[i] for i in range(n - 1)])[:n - k]))


IN = input
rint = lambda : int(IN())
rmint = lambda : map(int, IN().split())
rlist = lambda : list(rmint())
(n, k) = rmint()
a = rlist()
b = [a[i] - a[i + 1] for i in range(n - 1)]
b.sort()
print(a[-1] - a[0] + sum(b[:k - 1]))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
b = [a[i + 1] - a[i] for i in range(n - 1)]
b.sort()
print(sum(b[:n - k]))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
d = [[] for i in range(n - 1)]
for i in range(1, n):
	d[i - 1].append(arr[i] - arr[i - 1])
	d[i - 1].append(i - 1)
ds = d.copy()
ds.sort(reverse=True)
barr = [False] * (n - 1)
for i in range(k - 1):
	barr[ds[i][1]] = True
f = False
fn = 0
dr = 0
r = 0
for i in range(n - 1):
	if barr[i]:
		if f:
			r += arr[i] - fn
			f = False
		fn = 0
	elif f:
		continue
	else:
		fn = arr[i]
		f = True
if f:
	r += arr[n - 1] - fn
print(r)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [(a[i] - a[i - 1], i - 1) for i in range(1, n)]
b = sorted(b)[::-1]
b = [b[i][1] + 1 for i in range(k - 1)]
b = sorted(b)
b.append(n)
s = 0
st = 0
for i in b:
	s += a[i - 1] - a[st]
	st = i
print(s)


(n, k) = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
diff = []
for (a1, a2) in zip(a[:], a[1:]):
	diff.append(a2 - a1)
diff.sort()
print(sum(diff) - sum(diff[::-1][:k - 1]))


(n, k) = map(int, input().split())
array = list(map(int, input().split()))
pairs = []
for i in range(n - 1):
	pairs.append(array[i + 1] - array[i])
pairs.sort(reverse=True)
print(sum(pairs[k - 1:]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k == 1:
	print(a[-1] - a[0])
	exit()
if k == n:
	print('0')
	exit()
f = 0
b = []
for i in range(n - 1):
	if a[i] == a[i + 1]:
		continue
	b.append(a[i])
b.append(a[-1])
nn = len(b)
if k >= nn:
	print('0')
	exit()
c = []
for i in range(1, n):
	c.append([a[i] - a[i - 1], i])
c.sort(reverse=True)
ans = 0
d = []
for i in range(k - 1):
	d.append(c[i][1])
d.sort()
d.append(n)
m = a[0]
for i in range(len(d)):
	ans += a[d[i] - 1] - m
	if i == len(d) - 1:
		break
	m = a[d[i]]
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
kk = []
ans = abs(l[0] - l[-1])
for t in range(n - 1):
	kk.append(-l[t + 1] + l[t])
kk.sort()
for t in range(k - 1):
	ans += kk[t]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = []
for q in range(n - 1):
	s.append([a[q + 1] - a[q], q])
s.sort(reverse=True)
d = {q[1] for q in s[:k - 1]}
ans = 0
q1 = a[0]
for q in range(n - 1):
	if q in d:
		ans += a[q] - q1
		q1 = a[q + 1]
print(ans + a[-1] - q1)


(n, k) = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
b = [0] * n
for i in range(n - 1):
	b.append(a[i] - a[i + 1])
b.sort()
print(sum(b[:k - 1]) + max(a) - min(a))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a = a[::-1]
s = [a[0]]
S = 0
for x in a[1:]:
	s.append(s[-1] + x)
S += s[-1]
s.pop()
k -= 1
s = sorted(s)
i = 0
while i <= k - 1:
	S += s.pop()
	i += 1
print(S)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * (n - 1)
for i in range(n - 1):
	b[i] = a[i + 1] - a[i]
b.sort()
i = 0
ans = 0
while n != k:
	ans += b[i]
	i += 1
	n -= 1
print(ans)


(a, b) = map(int, input().split())
z = list(map(int, input().split()))
k = [0] * (a - 1)
for i in range(1, a):
	k[i - 1] = z[i] - z[i - 1]
print(sum(sorted(k, reverse=True)[b - 1:]))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
cost = l[n - 1] - l[0]
if k == 1:
	print(cost)
else:
	diff = [0 for _ in range(n - 1)]
	for i in range(n - 1):
		diff[i] = l[i + 1] - l[i]
	diff = sorted(diff)
	diff.reverse()
	print(cost - sum(diff[:k - 1]))


(n, k) = map(int, input().split())
l = [int(s) for s in input().split()]
re1 = []
re1.append(0)
for i in range(1, n):
	re = l[i] - l[i - 1]
	re1.append(re)
re1.sort(reverse=True)
su = 0
for i in range(k - 1, n):
	su += re1[i]
print(su)


import operator
(q, m) = input().split()
n = int(q)
k = int(m)
arr = list(map(int, input().split()))
if n == k:
	print(0)
elif k == 1:
	print(arr[-1] - arr[0])
else:
	d = dict()
	s = set()
	for i in range(n - 1):
		d[i] = arr[i + 1] - arr[i]
	for (key, value) in sorted(d.items(), reverse=True, key=lambda x: x[1]):
		if k > 1:
			s.add(key)
			k -= 1
		else:
			break
	ans = 0
	q = 0
	for i in sorted(s):
		ans += arr[i] - arr[q]
		q = i + 1
	ans += arr[-1] - arr[q]
	print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
poss = sorted([a[i - 1] - a[i] for i in range(1, n)])
ans = a[-1] - a[0]
for i in range(k - 1):
	ans += poss[i]
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ll = []
for i in range(n - 1):
	ll.append(l[i + 1] - l[i])
ll.sort()
print(sum(ll[:n - k]))


import sys
(n, k) = list(map(int, sys.stdin.readline().strip().split()))
a = list(map(int, sys.stdin.readline().strip().split()))
L = [a[-1]] * n
for i in range(1, n):
	L[i] = L[i - 1] + a[n - i - 1]
x = L.pop()
L.sort()
for i in range(0, k - 1):
	x = x + L[n - 2 - i]
print(x)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
s = 0
for x in a[::-1]:
	s += x
	b.append(-s)
if k == 1:
	print(-b[-1])
else:
	d = sorted(b[:-1])
	print(-sum(d[:k - 1]) - b[-1])


(n, k) = map(int, input().split())
arr = reversed(list(map(int, input().split())))
sum = 0
suff = []
for x in arr:
	sum += x
	suff.append(sum)
suff.pop()
ans = sum
suff = sorted(suff, reverse=True)
for i in range(k - 1):
	ans += suff[i]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
md = list()
for i in range(n - 1):
	md.append(a[i + 1] - a[i])
md.sort()
print(sum(md[:n - k]))


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [a[i + 1] - a[i] for i in range(len(a) - 1)]
b.sort()
if k == 1:
	print(sum(b))
else:
	print(sum(b) - sum(b[-k + 1:]))


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
s = 0
S = []
for i in reversed(range(n)):
	s += A[i]
	if i != 0:
		S.append(s)
S.sort(reverse=True)
ans = s + sum(S[0:k - 1])
print(ans)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
a1 = []
c = 0
for i in range(n - 1):
	a1.append(arr[i + 1] - arr[i])
a1.sort()
for g in range(0, n - m):
	c += a1[g]
print(c)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [a[i + 1] - a[i] for i in range(len(a) - 1)]
b.sort(reverse=True)
print(sum(b) - sum(b[0:k - 1]))


from heapq import heapify, heappop, heappush
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
inf = 100000000000
diff = []
for i in range(1, n):
	heappush(diff, (inf - (A[i] - A[i - 1]), inf - i))
Index = [0] * (k - 1)
for i in range(k - 1):
	(d, idx) = heappop(diff)
	d = inf - idx
	idx = inf - idx
	Index[i] = idx
Index.sort()
last = 0
ans = 0
for i in range(k - 1):
	ans += A[Index[i] - 1] - A[last]
	last = Index[i]
ans += A[n - 1] - A[last]
print(ans)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
a = []
ans = arr[-1] - arr[0]
for i in range(n - 1):
	a.append(-arr[i + 1] + arr[i])
a.sort()
print(ans + sum(a[:k - 1]))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
v = []
for i in range(n - 1):
	v.append(arr[i + 1] - arr[i])
v.sort(reverse=True)
res = arr[-1] - arr[0]
sm = 0
for i in range(k - 1):
	sm += v[i]
res = res - sm
print(res)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
diff = []
if n == 1:
	print(0)
else:
	for i in range(n - 1):
		diff.append(a[i + 1] - a[i])
	diff.sort(reverse=True)
	ans = a[-1] - a[0]
	for i in range(min(k - 1, len(diff))):
		ans -= diff[i]
	print(ans)


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
if k == n:
	print(0)
elif k == 1:
	print(max(a) - min(a))
else:
	b = [0] * (n - 1)
	for i in range(1, n):
		b[i - 1] = (a[i] - a[i - 1], i - 1)
	b = sorted(b)[::-1]
	if k == n - 1:
		print(b[-1][0])
	else:
		s = 0
		bps = []
		for i in range(k - 1):
			bp = b[i][1]
			bps.append(bp + 1)
		bps = sorted(bps)
		bps.append(n)
		st = 0
		for i in bps:
			s += a[i - 1] - a[st]
			st = i
		print(s)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
ans = a[n - 1] - a[0]
c = 0
for j in range(1, n):
	a[j - 1] -= a[j]
	if a[j - 1]:
		c += 1
a = sorted(a[:n - 1])
if c < k:
	print(0)
else:
	for j in range(k - 1):
		ans += a[j]
	print(ans)


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def bfs(adj, peoples):
	stack = [0]
	order = []
	parent = [-1] * len(adj)
	subt = peoples[:]
	while stack:
		v = stack.pop()
		order.append(v)
		for dest in adj[v]:
			if parent[v] == dest:
				continue
			parent[dest] = v
			stack.append(dest)
	for v in reversed(order):
		if v != 0:
			subt[parent[v]] += subt[v]
	return (order, subt, parent)

def main():
	from itertools import accumulate
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	acc = list(accumulate(reversed(a)))
	print(acc[-1] + sum(sorted(acc[:-1], reverse=True)[:k - 1]))
main()


(n, k) = map(int, input().split())
if n == 1:
	print(0)
	exit(0)
aa = list(map(int, input().split()))
d = []
for i in range(1, n):
	d.append(aa[i] - aa[i - 1])
d.sort(reverse=True)
print(aa[-1] - aa[0] - sum(d[:k - 1]))


from bisect import bisect_right as br

def f(k, a):
	d = []
	for i in range(0, len(a) - 1):
		d.append(a[i + 1] - a[i])
	ans = a[-1] - a[0]
	d = sorted(d, reverse=True)
	for i in range(k - 1):
		ans -= d[i]
	return ans
(a, b) = map(int, input().strip().split())
lst = list(map(int, input().strip().split()))
print(f(b, lst))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
dupa = [l[i + 1] - l[i] for i in range(n - 1)]
dupa.sort()
dupa.reverse()
print(l[-1] - l[0] - sum(dupa[:k - 1]))


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))
mod = 1000000007

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]

def N():
	return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def YES():
	print('YES')

def NO():
	print('NO')

def Yes():
	print('Yes')

def No():
	print('No')
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def lcm(a, b):
	return abs(a // gcd(a, b) * b)

def comb(n, r):
	if n < r:
		return 0
	else:
		return fac[n] * (finv[r] * finv[n - r] % mod) % mod

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def arr1d(n, v):
	return [v] * n

def arr2d(n, m, v):
	return [[v] * m for _ in range(n)]

def arr3d(n, m, p, v):
	return [[[v] * p for _ in range(m)] for i in range(n)]

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	(n, k) = sep()
	ar = lis()
	s = suffix_sum(ar)
	temp = sorted(s[1:], reverse=True)
	ans = s[0] + sum(temp[:k - 1])
	print(ans)
solve()


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = []
for i in range(n - 1):
	a.append(l[i + 1] - l[i])
sum1 = l[-1] - l[0]
a.sort(reverse=True)
sum1 -= sum(a[:k - 1])
print(sum1)


def gns():
	return list(map(int, input().split()))
(n, k) = gns()
ns = gns()
sm = [ns[-1]]
for i in reversed(range(n - 1)):
	sm.append(sm[-1] + ns[i])
ans = sm.pop()
sm.sort()
if k > 1:
	ans += sum(sm[-k + 1:])
print(ans)


import os
import sys
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 998244353
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
(n, k) = value()
a = array()
ans = a[-1] - a[0]
d = sorted([-a[i] + a[i - 1] for i in range(1, n)])
ans += sum(d[:k - 1])
print(ans)


(n, k) = map(int, input().split())
A = [int(i) for i in input().split()]
B = list()
for i in range(1, n):
	B.append(A[i] - A[i - 1])
B.sort()
print(sum(B[:n - k]))


import sys
input = sys.stdin.readline
(N, K) = map(int, input().split())
A = list(map(int, input().split()))
s = 0
B = []
for i in reversed(range(N)):
	s += A[i]
	B.append(s)
ans = B.pop()
B.sort(reverse=True)
for i in range(K - 1):
	ans += B[i]
print(ans)


(n, k) = map(int, input().split())
lis = list(map(int, input().split()))
for i in range(n - 2, -1, -1):
	lis[i] += lis[i + 1]
ans = lis.pop(0)
lis.sort(reverse=True)
print(ans + sum(lis[:k - 1]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cost = 0
diff = []
for i in range(0, n - 1):
	diff.append(a[i + 1] - a[i])
diff.sort()
print(sum(diff[0:len(diff) - k + 1]))


Input = lambda : map(int, input().split())
(n, k) = Input()
arr = list(Input())
diff = []
for i in range(n - 1):
	diff.append(arr[i + 1] - arr[i])
diff.sort()
print(sum(diff[:n - k]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
p = [0]
for i in a[::-1]:
	p.append(p[-1] + i)
p = p[::-1]
ans = p[0]
ans += sum(sorted(p[1:-1], reverse=True)[:k - 1])
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
c = a[-1] - a[0]
d = [a[i] - a[i - 1] for i in range(1, n)]
d = sorted(d)[::-1]
c -= sum(d[:k - 1])
print(c)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, k) = f()
if n == k:
	print(0)
	exit(0)
diff = []
l = il()
for i in range(1, n):
	diff.append(l[i] - l[i - 1])
diff.sort(reverse=True)
print(sum(diff[k - 1:]))


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)

def bo(i):
	return ord(i) - ord('a')
t = 1
while t > 0:
	t -= 1
	(n, k) = mi()
	a = li()
	suf = [0]
	for i in range(n - 1, -1, -1):
		suf.append(suf[-1] + a[i])
	suf = suf[1:]
	c = suf[-1] + sum(sorted(suf[:n - 1], reverse=True)[:k - 1])
	print(c)


fst = list(map(int, input().split()))
elements = list(map(int, input().split()))
diff = [0] * (len(elements) - 1)
for i in range(len(elements) - 1):
	diff[i] = elements[i + 1] - elements[i]
diff.sort()
print(sum(diff[:-(fst[1] - 1)])) if fst[1] != 1 else print(sum(diff))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if n == k:
	print(0)
elif k == 1:
	print(a[n - 1] - a[0])
else:
	x = []
	for i in range(1, n):
		y = a[i] - a[i - 1]
		x.append(y)
	x.sort()
	ans = sum(x[:n - k])
	print(ans)


(n, k) = list(map(int, input().split()))
li = list(map(int, input().split()))
li2 = []
for i in range(n - 1):
	li2.append(li[i] - li[i + 1])
li2.sort()
res = li[n - 1] - li[0]
res += sum(li2[:k - 1])
print(res)


(n, k) = map(int, input().split())
list = [x for x in map(int, input().split())]
differs = []
for i in range(1, len(list)):
	differs.append(list[i] - list[i - 1])
differs.sort()
differs.reverse()
ans = list[n - 1] - list[0]
for i in range(k - 1):
	ans -= differs[i]
print(ans)


import sys

def main():
	(n, k) = [int(x) for x in sys.stdin.readline().split(' ')]
	a = [int(x) for x in sys.stdin.readline().split(' ')]
	suffix = []
	if n == k:
		return sum((elem * (i + 1) for (i, elem) in enumerate(a)))
	c = 0
	for i in range(n - 1, 0, -1):
		c += a[i]
		suffix.append(c)
	suffix.sort(key=lambda x: x)
	suffix.reverse()
	return sum(suffix[:k - 1]) + sum(a)
print(main())


import sys
I = lambda : map(int, sys.stdin.readline().split())
(n, m) = I()
li = list(I())
l1 = []
ans = li[-1] - li[0]
for i in range(1, n):
	l1.append(li[i] - li[i - 1])
if m == n:
	exit(print('0'))
l1.sort()
l1 = l1[::-1]
for i in range(m - 1):
	ans = ans - l1[i]
print(ans)


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(''.join([str(x) for x in a]) + '\n')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = 1
for _ in range(t):
	(n, k) = li()
	a = li()
	suf = []
	cur = 0
	for i in range(n - 1, -1, -1):
		cur += a[i]
		suf.append(cur)
	ans = suf[-1]
	suf = suf[::-1]
	suf = suf[1:]
	suf.sort(reverse=True)
	for i in range(k - 1):
		ans += suf[i]
	print(ans)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
L = [0]
for i in A[::-1]:
	L.append(L[-1] + i)
k = L[-1] + sum(sorted(L[1:-1])[N - K:])
print(k)


[n, k] = list(map(int, input().split()))
arr = list(map(int, input().split()))
dp = [0] * n
sol = arr[n - 1] - arr[0]
for i in range(n):
	dp[i] = arr[i]
for i in range(n - 1):
	dp[i] = arr[i + 1] - arr[i]
dp[n - 1] = -arr[n - 1]
dp.sort(reverse=True)
for i in range(k - 1):
	sol -= dp[i]
print(sol)


import heapq
(N, K) = map(int, input().split())
arr = list(map(int, input().split()))
total = arr[-1] - arr[0]
best = total - sum(heapq.nlargest(K - 1, [arr[i] - arr[i - 1] for i in range(1, N)]))
print(best)


(m, n) = map(int, input().split())
l = list(map(int, input().split()))
p = []
if n == m:
	print(0)
elif n == 1:
	print(l[-1] - l[0])
else:
	p = {}
	for i in range(0, len(l) - 1):
		p[i] = l[i + 1] - l[i]
	r = list(sorted(p.items(), key=lambda t: t[1]))
	c = []
	for i in range(1, n):
		c.append(r[-i][0])
	c = sorted(c)
	t = 0
	ans = 0
	for i in range(0, len(c)):
		ans += l[c[i]] - l[t]
		t = c[i] + 1
	print(ans + l[-1] - l[t])


(n, k) = map(int, input().split())
given_array = list(map(int, input().split()))
first = []
for i in range(n - 1):
	x = given_array[i + 1] - given_array[i]
	first.append(x)
temp = sorted(first)
for _ in range(k - 1):
	temp.pop()
cost = sum(temp)
print(cost)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
INTERVAL = [A[i] - A[i - 1] for i in range(1, n)]
ANS = A[-1] - A[0]
INTERVAL.sort(reverse=True)
ANS -= sum(INTERVAL[:k - 1])
print(ANS)


import math
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
M = 10 ** 9 + 7

def isprime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def Freq(l):
	f = {}
	for i in l:
		if i in f:
			f[i] += 1
		else:
			f[i] = 1
	return f
inp = lambda : int(stdin.readline())
sip = lambda : stdin.readline()
mulip = lambda : map(int, stdin.readline().split())
lst = lambda : list(map(int, stdin.readline().split()))
slst = lambda : list(sip())
(n, k) = mulip()
A = lst()
B = []
for i in range(1, n):
	B.append(A[i] - A[i - 1])
B = sorted(B)
print(sum(B[:n - k]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = a[n - 1] - a[0]
dif = []
for i in range(1, n):
	dif.append(a[i] - a[i - 1])
dif.sort()
if k == 1:
	print(ans)
else:
	ans -= sum(dif[-k + 1:])
	print(ans)


from sys import stdin
(n, k) = map(int, stdin.readline().strip().split())
a = [int(x) for x in stdin.readline().strip().split()]
b = [a[i + 1] - a[i] for i in range(len(a) - 1)]
b.sort()
if k == 1:
	print(sum(b))
else:
	print(sum(b) - sum(b[-k + 1:]))


I = lambda : int(input())
IL = lambda : list(map(int, input().split()))
IF = lambda : list(map(float, input().split()))
(n, k) = IL()
A = IL()
B = sorted([a1 - a0 for (a0, a1) in zip(A[:-1], A[1:])])
print(sum(B[:n - k]))


(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
stack = []
for i in range(1, n):
	stack.append(ar[i] - ar[i - 1])
stack.sort()
print(sum(stack[:n - k]))


(n, k) = map(int, input().split())
g = list(map(int, input().split()))
ans = []
for i in range(1, n):
	ans.append(g[i] - g[i - 1])
l = n - k
su = 0
ans.sort()
for i in range(l):
	su += ans[i]
print(su)


import sys

def solve(a, n, k):
	cost = a[n - 1] - a[0]
	adj_differences = []
	for i in range(n - 1, 0, -1):
		adj_differences.append(a[i] - a[i - 1])
	adj_differences.sort()
	end = len(adj_differences) - 1
	for i in range(k - 1):
		cost -= adj_differences[end]
		end -= 1
	return cost
take = sys.stdin.readline
(n, k) = tuple(map(int, take().split()))
a = list(map(int, take().split()))
if n == 1:
	print(0)
else:
	result = solve(a, n, k)
	print(result)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a_len = len(a)
result = 0
if k == 1:
	print(a[a_len - 1] - a[0])
	exit(0)
r = []
for i in range(1, a_len):
	r.append(a[i] - a[i - 1])
r = sorted(r)
for i in range(k - 1):
	r.pop(len(r) - 1)
for i in range(len(r)):
	result += r[i]
print(result)


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
d = [a[i - 1] - a[i] for i in range(1, n)]
print(a[-1] - a[0] + sum(sorted(d)[:k - 1]))


for z in range(1):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == k:
		print(0)
		continue
	if k == 1:
		print(a[n - 1] - a[0])
		continue
	b = [a[i] - a[i - 1] for i in range(1, n)]
	b.sort()
	print(a[n - 1] - a[0] - sum(b[-(k - 1):]))


(n, k) = [int(s) for s in input().split()]
arr = [int(s) for s in input().split()]
if n == 1:
	print(0)
else:
	ans = arr[n - 1] - arr[0]
	parr = [0] * (n - 1)
	for i in range(len(arr) - 1):
		parr[i] = arr[i + 1] - arr[i]
	parr = sorted(parr)
	parr = parr[n - k:n]
	print(ans - sum(parr))


def main():
	line = input().split()
	n = int(line[0])
	k = int(line[1])
	line = input().split()
	v = [int(x) for x in line]
	l = []
	for i in range(0, n - 1):
		l.append(v[i] - v[i + 1])
	ans = v[n - 1] - v[0]
	k -= 1
	l.sort()
	pos = 0
	while k > 0:
		k -= 1
		ans += l[pos]
		pos += 1
	print(ans)
main()


import math, sys
from collections import Counter, defaultdict
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
(n, k) = li()
a = li()
c = []
s = a[n - 1] - a[0]
for i in range(1, n):
	c.append(a[i - 1] - a[i])
c.sort()
print(s + sum(c[:k - 1]))


def solve(n, k, ar):
	v = []
	for i in range(1, n):
		v.append(ar[i - 1] - ar[i])
	v.sort()
	res = ar[n - 1] - ar[0]
	for i in range(k - 1):
		res += v[i]
	print(res)
(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
solve(n, k, ar)


import sys

class CArraySplitting:

	def solve(self):
		(n, k) = [int(_) for _ in input().split()]
		a = [int(_) for _ in input().split()]
		ans = a[-1] - a[0]
		b = [a[u] - a[u + 1] for u in range(n - 1)]
		b.sort()
		ans += sum(b[:k - 1])
		print(ans)
solver = CArraySplitting()
input = sys.stdin.readline
solver.solve()


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
s = 0
S = []
for i in reversed(range(n)):
	s += A[i]
	if i != 0:
		S.append(s)
S.sort(reverse=True)
ans = s + sum(S[0:k - 1])
print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	(n, k) = RL()
	arr = RLL()
	res = -arr[0] + arr[-1]
	tmp = []
	for i in range(n - 1):
		tmp.append(arr[i] - arr[i + 1])
	tmp.sort()
	print(res + sum(tmp[:k - 1]))
main()


(n, m) = [int(x) for x in input().split()]
vals = [int(x) for x in input().split()]
diff = [y - x for (x, y) in zip(vals, vals[1:])]
diff = sorted(diff)
print(sum(diff[:n - m]))


nk = input().split(' ')
(n, k) = (int(nk[0]), int(nk[1]))
a = list(map(int, input().split(' ')))
if len(a) == 1:
	print('0')
	exit()
d = []
for i in range(1, n):
	d.append(a[i] - a[i - 1])
d.sort()
ans = 0
for i in range(n - k):
	ans += d[i]
print(ans)


(k, n) = map(int, input().split())
l = list(map(int, input().split()))
h = []
ans = l[-1] - l[0]
for i in range(k - 1):
	h.append(l[i + 1] - l[i])
h.sort()
h.reverse()
for i in range(n - 1):
	ans -= h[i]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
x = a[n - 1] - a[0]
for i in range(n - 1):
	a[i] = a[i] - a[i + 1]
a.sort()
print(sum(a[:k - 1]) + x)


from collections import defaultdict as dd
import math

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))
(n, k) = mi()
l = lm()
running = [0] * (n - 1)
for i in range(len(l) - 1):
	if i == 0:
		running[i] = (l[i], i + 1)
	else:
		running[i] = (running[i - 1][0] + l[i], i + 1)
running.sort()
sliced = running[:k - 1]
sliced.sort(key=lambda x: x[1])
cost = 0
last = 0
for i in range(len(sliced)):
	cost += (i + 1) * sum(l[last:sliced[i][1]])
	last = sliced[i][1]
cost += k * sum(l[last:])
print(cost)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l1 = []
k = n - k
for i in range(n - 1):
	l1.append(l[i + 1] - l[i])
l1.sort()
if n == k:
	print(0)
else:
	sum1 = 0
	for i in range(k):
		sum1 += l1[i]
	print(sum1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
print(max(a) - min(a) - sum(sorted([a[i + 1] - a[i] for i in range(len(a) - 1)], reverse=True)[:k - 1]))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if k == 1:
	print(l[-1] - l[0])
else:
	for i in range(1, n):
		l[-i] -= l[-i - 1]
	l.pop(0)
	l.sort()
	print(sum(l[:-k + 1]))


import sys

def comparator(tupleElem):
	return tupleElem[1]
(n, k) = sys.stdin.readline().split()
n = int(n)
k = int(k)
array = [int(i) for i in sys.stdin.readline().split()]
dif = []
for i in range(1, n):
	dif.append(array[i] - array[i - 1])
dif2 = list(enumerate(dif))
if k == 1:
	print(array[n - 1] - array[0])
else:
	top_k1 = sorted(dif2, key=comparator, reverse=True)[:k - 1]
	cost = array[-1] - array[0]
	for (index, val) in top_k1:
		cost -= val
	print(cost)


inp = list(map(int, input().split()))
n = inp[0]
k = inp[1]
inp = list(map(int, input().split()))
diff = []
for i in range(len(inp) - 1):
	diff.append(inp[i + 1] - inp[i])
diff.sort(reverse=True)
diff = diff[:k - 1]
print(inp[len(inp) - 1] - inp[0] - sum(diff))


from functools import reduce
import io
import os
import sys
from atexit import register
import random
import math
import itertools
DEBUG = False
STRESSTEST = False
if not DEBUG:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda : os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0

def nextStr():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = input().split()
		tokens_next = 0
	tokens_next += 1
	if type(tokens[tokens_next - 1]) == str:
		return tokens[tokens_next - 1]
	return tokens[tokens_next - 1].decode()

def nextInt():
	return int(nextStr())

def nextIntArr(n):
	return [nextInt() for i in range(n)]

def print(*argv, end='\n'):
	for arg in argv:
		sys.stdout.write((str(arg) + ' ').encode())
	sys.stdout.write(end.encode())

def genTestCase():
	n = random.randint(2, 20)
	k = random.randint(1, n)
	a = sorted((random.randint(1, 100) for i in range(n)))
	return (a, k)

def bruteforce(a, k):
	if k == 1:
		return a[-1] - a[0]
	res = math.inf
	for comb in itertools.combinations(range(1, len(a)), k - 1):
		subarrays = []
		cur = sorted(comb)
		for i in range(len(cur)):
			st = 0 if i == 0 else cur[i - 1]
			end = cur[i]
			subarrays.append(a[st:end])
		subarrays.append(a[cur[-1]:])
		diffs = map(lambda x: x[-1] - x[0], subarrays)
		curSum = sum(diffs)
		if curSum < res:
			res = curSum
	return res

def doStressTest():
	while True:
		curTest = genTestCase()
		mySoln = solve(*curTest)
		bruteforceSoln = bruteforce(*curTest)
		if mySoln != bruteforceSoln:
			print('### Found case ###')
			print(curTest)
			print(f'{mySoln} should have been: {bruteforceSoln}')
			return

def segWithMaxDiff(a, maxDiff):
	numSegments = 0
	st = 0
	while st < len(a):
		end = next((i for i in range(st, len(a)) if a[i] - a[st] > maxDiff), len(a))
		numSegments += 1
		st = end
	return numSegments

def getMinCost(a, maxDiff):
	cost = 0
	st = 0
	while st < len(a):
		end = next((i for i in range(st, len(a)) if a[i] - a[st] > maxDiff), len(a))
		cost += a[end - 1] - a[st]
		st = end
	return cost

def solve(a, k):
	diffs = [a[i] - a[i - 1] for i in range(1, len(a))]
	diffs = sorted(diffs, reverse=True)
	return a[-1] - a[0] - sum(diffs[:k - 1])

def solve1(a, k):
	low = -1
	high = a[-1] - a[0]
	while low + 1 < high:
		mid = (low + high) // 2
		if segWithMaxDiff(a, mid) <= k:
			high = mid
		else:
			low = mid
	return getMinCost(a, high)
if not DEBUG and STRESSTEST:
	raise Exception('Wrong flags!')
if STRESSTEST:
	doStressTest()
else:
	n = nextInt()
	k = nextInt()
	a = nextIntArr(n)
	res = solve(a, k)
	print(res)
sys.stdout.flush()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
al = a[-1] - a[0]
for i in range(n - 1):
	a[i] = a[i + 1] - a[i]
a.pop()
if k - 1 > n - k:
	a.sort()
	print(sum(a[:n - k]))
else:
	a.sort(reverse=True)
	print(al - sum(a[:k - 1]))


(n, k) = map(int, input().split())
(*a,) = map(int, input().split())
suff = [a[-1]]
for i in range(n - 2, -1, -1):
	suff.append(suff[-1] + a[i])
ans = suff.pop()
print(ans + sum((i for i in sorted(suff, reverse=True)[:k - 1])))


import sys
(n, k) = map(int, sys.stdin.readline().split())
c = list(map(int, sys.stdin.readline().split()))
dif = []
for i in range(1, n):
	dif.append(c[i] - c[i - 1])
dif.sort()
ans = 0
for i in range(n - k):
	ans += dif[i]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
diff = sorted([y - x for (x, y) in zip(a, a[1:])])
print(sum(diff[:n - k]))


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
from heapq import heappush as hpush
from heapq import heappop as hpop
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
(n, k) = ri()
arr = ri()
ans = arr[-1] - arr[0]
get = []
for i in range(1, len(arr)):
	get.append(arr[i - 1] - arr[i])
get.sort()
for i in range(k - 1):
	ans += get[i]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = [0] * (n - 1)
for i in range(n - 1):
	c[i] = a[i + 1] - a[i]
c.sort(reverse=True)
s = 0
for i in range(k - 1):
	s += c[i]
print(max(a) - min(a) - s)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class SegmentTree:

	def __init__(self, data, default=-10 ** 6, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(50001)]
pp = []

def SieveOfEratosthenes(n=50000):
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for i in range(50001):
		if prime[i]:
			pp.append(i)
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
suff = [0] * n
suff[-1] = a[-1]
for i in range(n - 2, -1, -1):
	suff[i] = suff[i + 1] + a[i]
s = sum(a)
suff = suff[1:]
suff.sort(reverse=True)
for i in range(k - 1):
	s += suff[i]
print(s)


def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	dp = [0] * (n - 1)
	for i in range(1, n):
		dp[i - 1] = a[i - 1] - a[i]
	dp.sort()
	ans = sum(dp[:k - 1])
	ans += a[-1] - a[0]
	print(ans)
	return
main()


from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n, k) = gil()
a = gil()
for i in range(1, n):
	a[i] += a[i - 1]
ans = a.pop()
a.sort()
print(k * ans - sum(a[:k - 1]))


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = 0
p = []
for i in range(n - 1, 0, -1):
	s += a[i]
	p.append(s)
p.sort()
p.reverse()
res = s + a[0]
for i in range(k - 1):
	res += p[i]
print(res)


(n, k) = map(int, input().split())
a = [int(o) for o in input().split()]
s = 0
arr = []
for i in range(1, n):
	arr.append(a[i] - a[i - 1])
	s += a[i] - a[i - 1]
arr = sorted(arr)
arr = arr[::-1]
print(s - sum(arr[:k - 1]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = []
for i in range(1, n):
	b.append([a[i] - a[i - 1], i - 1])
b.sort()
b = b[n - k:]
prev = -1
ans = 0
for i in b:
	ind = i[1]
	ans += a[ind] - a[prev + 1]
	prev = ind
ans += a[n - 1] - a[prev + 1]
print(ans)


from math import ceil, floor
from collections import defaultdict
for _ in range(1):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	temp = []
	for i in range(n - 1):
		temp.append(arr[i + 1] - arr[i])
	temp.sort()
	print(sum(temp[0:n - k]))


def main():
	(n, k) = map(int, input().split(' '))
	ip = [int(item) for item in input().split(' ')]
	print(sum(sorted([ip[i] - ip[i - 1] for i in range(1, len(ip))])[:n - k]))
main()


import os
from collections import Counter, defaultdict
from io import BytesIO, IOBase
import sys
from math import inf, ceil

def main():
	for i in range(1):
		(n, k) = map(int, input().split())
		a = [int(x) for x in input().split()]
		dp = []
		for j in range(1, n):
			dp.append(a[j] - a[j - 1])
		dp.sort(reverse=True)
		print(-sum(dp[:k - 1]) + a[-1] - a[0])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


line1 = input()
tmp = line1.split(' ')
(n, k) = (int(tmp[0]), int(tmp[1]))
line2 = input()
lst = [int(i) for i in line2.split(' ')]
gap = []
for i in range(n):
	if i:
		gap.append((lst[i] - lst[i - 1], i))
gap.sort(reverse=True)
ret = lst[n - 1] - lst[0]
for i in range(k - 1):
	ret -= lst[gap[i][1]] - lst[gap[i][1] - 1]
print(ret)


(n, k) = [int(u) for u in input().split()]
a = [int(u) for u in input().split()]
ans = a[-1] - a[0]
diff = [a[i - 1] - a[i] for i in range(1, len(a))]
diff.sort()
ans += sum(diff[0:k - 1])
print(ans)


(n, k) = map(int, input().split())
ls = list(map(int, input().split()))
lsn = [ls[i + 1] - ls[i] for i in range(n - 1)]
lsn.sort()
print(sum(lsn[:n - k]))


from sys import stdin
input = stdin.readline
INP = lambda : map(int, input().split())
(n, k) = INP()
(*a,) = INP()
print(sum(sorted((y - x for (x, y) in zip(a, a[1:])))[:n - k]))


(n, k) = list(map(int, input().strip().split()))
arr = list(map(int, input().strip().split()))
k -= 1
arr_new = sorted([arr[i + 1] - arr[i] for i in range(n - 1)], reverse=True)
print(arr[-1] - arr[0] - sum(arr_new[:k]))


def solve():
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	diff = [a[i] - a[i - 1] for i in range(1, n)]
	sort_diff = sorted(diff)
	ans = 0
	if k == 1:
		ans = a[n - 1] - a[0]
	elif k == n:
		ans = 0
	else:
		for i in range(n - k):
			ans += sort_diff[i]
	print(ans)
solve()


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	nk = list(map(int, input().split()))
	(n, k) = (nk[0], nk[1])
	a = list(map(int, input().split()))
	ans = a[len(a) - 1] - a[0]
	t = []
	for i in range(1, len(a)):
		t.append(a[i] - a[i - 1])
	st = sorted(t, reverse=True)
	for i in range(k - 1):
		ans -= st[i]
	print(ans)
main()


import heapq
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n - 2, -1, -1):
	a[i] += a[i + 1]
res = a[0] + sum(heapq.nlargest(k - 1, a[1:]))
print(res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = sorted([a[i] - a[i - 1] for i in range(1, n)], reverse=True)
ans = a[-1] - a[0]
for i in range(k - 1):
	ans -= l[i]
print(ans)


(n, k) = map(int, input().split())
l = [int(x) for x in input().split()]
s = l[-1] - l[0]
a = [0]
for i in range(1, n):
	a.append(l[i] - l[i - 1])
a = sorted(a)[::-1]
print(s - sum(a[:k - 1]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = a[n - 1] - a[0]
k -= 1
if k == 0:
	print(d)
elif k == n:
	print(0)
else:
	y = []
	for i in range(n - 1):
		y += [a[i + 1] - a[i]]
	y.sort()
	y = y[::-1]
	print(d - sum(y[:k]))


(n, k) = [int(x) for x in input().split()]
L = [int(x) for x in input().split()]
D = []
for i in range(n - 1):
	D.append(L[i + 1] - L[i])
s = 0
D.sort(reverse=True)
for i in range(k - 1):
	s += D[i]
print(L[-1] - L[0] - s)


l = input().split()
n = int(l[0])
k = int(l[1])
l = input().split()
li = [int(i) for i in l]
l = []
for i in range(1, n):
	l.append(li[i] - li[i - 1])
l.sort()
sumi = li[-1] - li[0]
for i in range(k - 1):
	sumi -= l[-(i + 1)]
print(sumi)


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
print(-lst[0] + lst[-1] + sum(sorted([lst[i] - lst[i + 1] for i in range(n - 1)])[:k - 1]))


import heapq
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = [0 for i in range(n)]
s[0] = a[0]
for i in range(1, n):
	s[i] = s[i - 1] + a[i]
x = s.pop()
x *= k
heapq.heapify(s)
for _ in range(k - 1):
	x -= heapq.heappop(s)
print(x)


import sys
import math
input = sys.stdin.readline
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
diff = []
for i in range(1, n):
	diff.append(arr[i] - arr[i - 1])
ans = sum(diff)
diff.sort(reverse=True)
for i in range(k - 1):
	ans -= diff[i]
print(ans)


(n, k) = map(int, input().split())
k -= 1
numbers = list(map(int, input().split()))
differences = [0] * n
differences[0] = (0, 0)
for i in range(1, n):
	differences[i] = (numbers[i] - numbers[i - 1], i)
differences.sort()
minus = 0
for i in range(1, k + 1):
	minus += differences[-i][0]
print(numbers[-1] - numbers[0] - minus)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = a[-1] - a[0]
b = sorted((a[i] - a[i - 1] for i in range(1, n)))
while k > 1:
	c -= b.pop()
	k -= 1
print(c)


(n, k) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
dp = []
for i in range(n - 1):
	dp.append(arr[i] - arr[i + 1])
dp.sort()
s = 0
for i in range(k - 1):
	s += dp[i]
s += arr[n - 1] - arr[0]
print(s)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
if 1 <= k <= n <= 3 * 10 ** 5 and len(a) == n:
	for i in range(len(a)):
		if 1 <= a[i] <= 10 ** 9:
			continue
		else:
			break
	a.sort()
	mass = []
	if k == n:
		rez = 0
	elif k == 1:
		rez = a[-1] - a[0]
	else:
		for i in range(len(a)):
			if i == len(a) - 1:
				continue
			else:
				t = a[i + 1] - a[i]
				mass.append(t)
		mass.sort()
		razn = n - k
		l = []
		for i in range(razn):
			l.append(mass[i])
		rez = sum(l)
	print(rez)


import math
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = []
for i in range(n - 1):
	d.append(a[i + 1] - a[i])
d.sort()
print(sum(d[0:n - k]))


import sys
from collections import defaultdict
import math

def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = sorted([a[i] - a[i - 1] for i in range(1, n)], reverse=True)
	print(a[-1] - a[0] - sum(d[:k - 1]))
main()


def main():
	(n, k) = [int(s) for s in input().split()]
	a = [int(s) for s in input().split()]
	diffs = [a[i + 1] - a[i] for i in range(n - 1)]
	diffs.sort()
	print(sum(diffs[:n - k]))
main()


from sys import stdin
read = stdin.readline
(n, k) = map(int, read().split())
a = list(map(int, read().split()))
b = sorted((a[i + 1] - a[i] for i in range(n - 1)))
print(a[-1] - a[0] - sum(b[n - k:]))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [0 for _ in range(n - 1)]
for i in range(1, n):
	b[i - 1] = a[i] - a[i - 1]
b.sort()
res = 0
for i in range(n - k):
	res += b[i]
print(res)


def arr007_array_splitting(n, k, a):
	for i in range(n - 2, -1, -1):
		a[i] += a[i + 1]
	b = []
	for i in range(1, n):
		b.append(a[i])
	b.sort()
	res = a[0]
	for i in range(n - 2, n - k - 1, -1):
		res += b[i]
	return res
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
result = arr007_array_splitting(n, k, a)
print(result)


(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
gap = []
for i in range(1, len(ar)):
	gap.append(ar[i] - ar[i - 1])
gap = sorted(gap)
ans = 0
for i in range(0, n - k):
	ans += gap[i]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k == 1:
	print(max(a) - min(a))
	return
dif = []
for i in range(n - 1):
	dif.append(a[i + 1] - a[i])
dif = sorted(dif)
print(sum(dif[:-k + 1]))


R = lambda : map(int, input().split())
(n, k) = R()
a = (*R(),)
print(sum(sorted((y - x for (x, y) in zip(a, a[1:])))[:n - k]))


(n, k) = [int(p) for p in input().split()]
arr = [int(p) for p in input().split()]
diff = []
for i in range(1, n):
	diff.append(arr[i] - arr[i - 1])
diff.sort()
print(sum(diff[:n - k]))


(n, k) = map(int, input().strip().split(' '))
a = list(map(int, input().strip().split(' ')))
cnt = []
cnt.append(a[-1])
for i in range(1, n):
	cnt.append(cnt[i - 1] + a[-(i + 1)])
ans = cnt[-1]
del cnt[-1]
cnt.sort(reverse=True)
ans += sum(cnt[:k - 1])
print(ans)


(n, k) = map(int, input().split())
A = [int(i) for i in input().split()]
suff = []
sumi = 0
for i in range(n - 1, 0, -1):
	sumi += A[i]
	suff.append(sumi)
suff.sort(reverse=True)
ans = sum(suff[:k - 1])
ans += sum(A)
print(ans)


def main():
	import sys
	input = sys.stdin.readline
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	kek = [0] * (n - 1)
	for i in range(n - 1):
		kek[i] = -arr[i + 1] + arr[i]
	kek.sort()
	ans = arr[-1] - arr[0]
	for i in range(k - 1):
		ans += kek[i]
	print(ans)
	return 0
main()


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
if N == 1:
	print(0)
else:
	B = [A[i + 1] - A[i] for i in range(N - 1)]
	B.sort(reverse=True)
	print(sum(B[K - 1:]))


(n, k) = [int(i) for i in input().split()]
data = [int(i) for i in input().split()]
newd = [0] * n
newd[-1] = data[-1]
for i in range(n - 2, -1, -1):
	newd[i] = data[i] + newd[i + 1]
a = newd[0]
newd.sort()
if k == 1:
	ans = a
elif newd[n + 1 - k] > a:
	ans = a + sum(newd[n + 1 - k:])
else:
	ans = sum(newd[n - k:])
print(ans)


(a, b) = list(map(int, input().split()))
d = list(map(int, input().split()))
minn = 1000000000000000000000
c = [d[0]]
for i in range(1, a):
	if c[-1] != d[i]:
		c.append(d[i])
a = len(c)
if b >= a:
	print(0)
	exit()
d = []
for i in range(1, a):
	d.append(c[i] - c[i - 1])
ans = c[-1] - c[0]
d.sort(reverse=True)
for i in range(b - 1):
	ans -= d[i]
print(ans)


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
ans = arr[-1] - arr[0]
new = []
for i in range(1, n):
	new += [arr[i] - arr[i - 1]]
new.sort()
new = new[::-1]
tosub = [0]
for i in range(k - 1):
	tosub += [new[i]]
for num in tosub:
	ans -= num
print(ans)


def mlt():
	return map(int, input().split())
(x, y) = mlt()
s = list(mlt())
res = s[-1] - s[0]
v = []
for n in range(1, x):
	v.append(s[n] - s[n - 1])
vv = sum(sorted(v, reverse=True)[:y - 1])
print(res - vv)


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
diff = []
for i in range(1, n):
	diff.append(arr[i - 1] - arr[i])
diff.sort()
res = arr[n - 1] - arr[0]
res += sum(diff[0:k - 1])
print(res)


import math
from operator import itemgetter
x = list(map(int, input().split()))
y = list(map(int, input().split()))
ii = x[0]
jj = x[1]
c = []
for i in range(ii - 1):
	c.append([i, y[i + 1] - y[i]])
c.sort(key=itemgetter(1), reverse=True)
X = 0
for i in range(jj - 1):
	X = X + c[i][1]
print(+max(y) - min(y) - X)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
from fractions import Fraction
import heapq as hp
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
(n, k) = Ri()
a = Ri()
suffix = [0] * n
suffix[n - 1] = a[n - 1]
for i in range(len(a) - 2, -1, -1):
	suffix[i] = suffix[i + 1] + a[i]
suffix = suffix[1:]
suffix.sort(reverse=True)
summ = sum(a)
for i in range(k - 1):
	summ += suffix[i]
print(summ)


(n, k) = map(int, input().split())
a = [*map(int, input().split())]
for i in range(n - 1, 0, -1):
	a[i - 1] += a[i]
ans = a[0]
a[0] = -1e+18
a = sorted(a)
if k > 1:
	ans += sum(a[n - k + 1:n])
print(ans)


(n, k) = map(int, input().split())
data = []
data[:] = map(int, input().split())
newd = []
for i in range(len(data) - 1):
	newd.append(data[i + 1] - data[i])
newd.sort()
ans = 0
for i in range(n - k):
	ans += newd[i]
print(ans)


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
R = lambda : map(int, input().split())
(n, k) = R()
l = list(R())
lst = []
for i in range(1, n):
	lst.append(l[i - 1] - l[i])
lst.sort()
res = l[n - 1] - l[0]
for i in range(k - 1):
	res += lst[i]
print(res)


def calccost(arr, start, stop):
	return arr[start] - arr[stop]
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sp = [-1] * k
dic = []
for i in range(n - 1):
	temp = [i, a[i + 1] - a[i]]
	dic.append(temp)
dic.sort(key=lambda x: x[1], reverse=True)
split = []
for i in range(k - 1):
	split.append(dic[i][0])
split.sort()
start = 0
cost = 0
if k == 1:
	cost = calccost(a, 0, -1)
else:
	for i in split:
		cost += calccost(a, start, i)
		start = i + 1
	cost += calccost(a, start, -1)
print(-cost)


import math
(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = []
a.reverse()
counter = 0
for i in range(n - 1):
	counter += a[i]
	b.append(counter)
b.sort(reverse=True)
print(sum(b[:k - 1]) + sum(a))


def pro(arr, k):
	d = []
	for i in range(1, len(arr)):
		d.append(arr[i - 1] - arr[i])
	d.sort()
	ans = arr[-1] - arr[0]
	for i in range(k - 1):
		ans += d[i]
	print(ans)
(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
pro(arr, k)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
p = [0]
for x in a[::-1]:
	p.append(p[-1] + x)
ans = p[-1] + sum(sorted(p[1:-1])[n - k:])
print(ans)


A = input().split()
A = map(int, A)
A = list(A)
N = A[0]
K = A[1]
A = input().split()
A = map(int, A)
A = list(A)
A.sort()
total = A[-1] - A[0]
B = []
for i in range(0, N - 1):
	B.append(A[i + 1] - A[i])
B.sort()
for i in range(N - 1 - K + 1, N - 1):
	total -= B[i]
print(total)


(n, k) = map(int, input().split())
sttr = map(int, input().split())
a = list(sttr)
b = []
for i in range(n - 1):
	b.append(a[i + 1] - a[i])
b.sort()
b.reverse()
summ = 0
for i in range(k - 1, n - 1):
	summ += b[i]
print(summ)


(n, k) = map(int, input().split())
data = list(map(int, input().split()))
dataS = []
for (i, d) in enumerate(data):
	if i == 0:
		continue
	dataS.append((i, d - data[i - 1]))
dataS.sort(key=lambda x: x[1], reverse=True)
dataIndex = []
try:
	for i in range(k - 1):
		dataIndex.append(dataS[i][0])
except:
	print(0)
	exit()
dataIndex.sort()
result = 0
minI = 0
maxI = 0
for i in range(0, k - 1):
	maxI = dataIndex[i]
	result += data[maxI - 1] - data[minI]
	minI = maxI
result += data[-1] - data[maxI]
print(result)


from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
mod = 10 ** 9 + 7
eps = 10 ** (-7)

def inp():
	return int(input())

def inpl():
	return list(map(int, input().split()))

def inpl_str():
	return list(input().split())
(N, K) = inpl()
aa = inpl()
bb = []
for i in range(N - 1):
	tmp = aa[i + 1] - aa[i]
	bb.append(tmp)
bb.sort()
print(sum(bb[:N - K]))


o = input().rstrip().split(' ')
p = input().rstrip().split(' ')
if int(o[0]) == int(o[1]):
	print(0)
elif int(o[1]) == 1:
	print(int(p[len(p) - 1]) - int(p[0]))
else:
	l = []
	G = 0
	for i in range(0, len(p) - 1):
		if 1:
			l.append(int(p[i + 1]) - int(p[i]))
	l.sort(key=int)
	for i in range(0, len(p) - int(o[1])):
		G += int(l[i])
	print(G)


nk = input().split()
n = int(nk[0])
k = int(nk[1])
a = [int(i) for i in input().split()]
if k == n:
	print(0)
else:
	dif = []
	for i in range(1, n):
		dif.append(a[i] - a[i - 1])
	dif.sort(reverse=True)
	ans = 0
	for i in range(k - 1, len(dif)):
		ans += dif[i]
	print(ans)


from heapq import heappush, heappop
from collections import deque
import sys
sys.setrecursionlimit(10 ** 6)

def MI():
	return map(int, input().split())

def I():
	return int(input())

def LI():
	return [int(i) for i in input().split()]
YN = ['YES', 'NO']

def bisect(ls, x):
	(l, r) = (0, len(ls))
	while r - l > 1:
		mid = (l + r) // 2
		if ls[mid] >= x:
			r = mid
		else:
			l = mid
	return l
q = 1
for _ in range(q):
	(n, k) = MI()
	if n == 1:
		print(0)
		exit()
	a = LI()
	b = []
	for i in range(n - 1):
		b.append(a[i + 1] - a[i])
	b.sort()
	print(sum(b[0:n - k]))


ll = lambda : list(map(int, input().split()))
testcases = 1
for testcase in range(testcases):
	[n, k] = ll()
	a = ll()
	da = [0]
	for i in range(1, n):
		da.append(a[i] - a[i - 1])
	da.sort(reverse=True)
	print(sum(da[k - 1:]))


def raspil(n, k, lst):
	b = list()
	for i in range(1, n):
		b.append(lst[i - 1] - lst[i])
	b.sort()
	result = lst[-1] - lst[0]
	for i in range(k - 1):
		result += b[i]
	return result
(N, K) = [int(j) for j in input().split()]
a = [int(x) for x in input().split()]
print(raspil(N, K, a))


(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
B = []
count = 1
for i in range(1, n):
	B.append([A[i] - A[i - 1], count])
	count += 1
B.sort(key=lambda x: x[0], reverse=True)
L = []
for val in range(k - 1):
	L.append(B[val][1])
L.sort()
L += [n]
Ans = 0
Temp = 0
for val in L:
	Ans += A[val - 1] - A[Temp]
	Temp = val
print(Ans)


(n, k) = map(int, input().split())
lt = [int(x) for x in input().split()]
dt = {}
diff = []
for i in range(n - 1):
	diff.append(lt[i] - lt[i + 1])
diff.sort()
sm = sum(diff[:k - 1])
print(sm - lt[0] + lt[-1])


(n, k) = map(int, input().split())
ai = list(map(int, input().split()))
if n == k:
	print(0)
else:
	difs = [0] * (n - 1)
	for i in range(n - 1):
		difs[i] = ai[i + 1] - ai[i]
	difs.sort()
	n2 = n - k
	ans = 0
	for i in range(n2):
		ans += difs[i]
	print(ans)


from sys import stdin
input = stdin.readline
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
diff = [a[i - 1] - a[i] for i in range(1, n)]
diff = sorted(diff)
res = 0
for i in range(k - 1):
	res += diff[i]
print(res + a[n - 1] - a[0])


a = list(map(int, input().split()))
b = a[0]
c = a[1]
d = list(map(int, input().split()))
e = [0] * (b - 1)
for i in range(0, b - 1):
	e[i] = d[i + 1] - d[i]
e.sort()
e.reverse()
f = 0
for i in range(0, c - 1):
	f = f + e[i]
print(d[b - 1] - d[0] - f)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list()
for j in range(n - 1):
	b.append(a[j + 1] - a[j])
b.sort()
if n == k:
	print(0)
else:
	print(sum(b[0:n - k]))


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
print(sum(sorted([arr[i + 1] - arr[i] for i in range(n - 1)])[:n - m]))


def naiveSolve(n):
	return

def main():
	(n, k) = readIntArr()
	a = readIntArr()
	diff = []
	for i in range(1, n):
		diff.append(a[i] - a[i - 1])
	diff.sort(reverse=True)
	total = a[n - 1] - a[0]
	ans = total
	for i in range(k - 1):
		ans -= diff[i]
	print(ans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(l, r):
	print('? {} {}'.format(l, r))
	sys.stdout.flush()
	return int(input())

def answerInteractive(x):
	print('! {}'.format(x))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
from math import gcd, floor, ceil
for _abc in range(1):
	main()


(n, k) = (*map(int, input().split()),)
a = [int(x) for x in input().split()]
jmps = [b - a for (a, b) in zip(a, a[1:n])]
jmps.sort(reverse=True)
print(a[-1] - a[0] - sum(jmps[:k - 1]))


(n, k) = map(int, input().split())
x = list(map(int, input().split()))
a = []
length = len(x)
for i in range(1, length):
	a.append(x[i] - x[i - 1])
a.sort(reverse=True)
a = a[:k - 1]
try:
	minimum = min(a)
except ValueError:
	print(max(x) - min(x))
	exit()
q = k - 1
q = q - len(a[:a.index(minimum)])
(ans, cur_min) = (0, x[0])
for j in range(1, length):
	if x[j] - x[j - 1] == minimum and q > 0:
		q -= 1
		ans += x[j - 1] - cur_min
		cur_min = x[j]
	elif x[j] - x[j - 1] > minimum:
		ans += x[j - 1] - cur_min
		cur_min = x[j]
	if j == length - 1:
		ans += x[j] - cur_min
print(ans)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
if k == 1:
	print(arr[-1] - arr[0])
	exit(0)
if n == k:
	print(0)
	exit(0)
ar = []
for i in range(n - 1):
	ar.append(arr[i] - arr[i + 1])
ar.sort()
ar = ar[:k - 1]
print(arr[-1] - arr[0] + sum(ar))


(n, k) = [int(x) for x in input().split()]
array = [int(x) for x in input().split()]
diff = [0] * (n - 1)
splits = []
for i in range(1, n):
	diff[i - 1] = array[i - 1] - array[i]
j = 0
answer = array[-1] - array[0]
diff.sort()
for i in diff:
	if k == 1:
		break
	k -= 1
	answer += i
print(answer)


def solve():
	(n, k) = (int(x) for x in input().split())
	arr = [int(x) for x in input().split()]
	d = [0 for _ in range(n - 1)]
	for i in range(n - 1):
		d[i] = arr[i + 1] - arr[i]
	d.sort()
	ans = sum(d[:n - k])
	print(ans)
solve()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	(n, k) = sep()
	a = lis()
	ans = a[n - 1] - a[0]
	hasve = []
	for i in range(n - 1):
		hasve.append(a[i] - a[i + 1])
	hasve = sorted(hasve)
	for i in range(k - 1):
		ans += hasve[i]
	print(ans)
testcase(1)


import sys
(n, k) = map(int, input().split())
nums = list(map(int, input().split()))
suffixSum = [nums[-1]]
for val in nums[-2::-1]:
	suffixSum.append(suffixSum[-1] + val)
ans = suffixSum[-1]
suffixSum = suffixSum[:-1]
suffixSum.sort(reverse=True)
ans += sum(suffixSum[:k - 1])
print(ans)


(n, k) = map(int, input().split())
a = list(map(float, input().split()))
b = []
m = 0
s = a[n - 1] - a[0]
for i in range(n - 1):
	t = a[i + 1] - a[i]
	b.append(t)
b.sort(reverse=True)
for i in range(k - 1):
	s -= b[i]
print(int(s))


import sys
import math

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	(n, m) = get_ints()
	arr = get_list()
	ans = []
	val = arr[-1] - arr[0]
	for i in range(1, n):
		ans.append(arr[i - 1] - arr[i])
	ans.sort()
	for i in range(m - 1):
		val += ans[i]
	print(val)


(n, k) = map(int, input().split())
(*m,) = map(int, input().split())
diff = []
for i in range(1, n):
	diff.append(m[i - 1] - m[i])
diff.sort()
res = m[-1] - m[0]
for i in range(k - 1):
	res += diff[i]
print(res)


(n, k) = map(int, input().split())
aa = list(map(int, input().split()))
ss = [0]
for a in reversed(aa):
	ss.append(ss[-1] + a)
ss = ss[1:]
if k == 1:
	print(ss[-1])
	exit(0)
print(ss[-1] + sum(sorted(ss[:-1])[-(k - 1):]))


class elem:

	def __init__(self, i, d):
		self.i = i
		self.d = d
iarr = list(map(int, input().split()))
n = iarr[0]
k = iarr[1]
arr = list(map(int, input().split()))
elemar = []
for i in range(n - 1):
	elemar.append(elem(i, arr[i + 1] - arr[i]))
elemar.sort(key=lambda x: x.d, reverse=True)
flagar = [0 for i in range(n)]
for i in range(k - 1):
	flagar[elemar[i].i] = 1
prev = 0
ans = 0
for i in range(n):
	if flagar[i] == 1:
		ans += arr[i] - arr[prev]
		prev = i + 1
ans += arr[-1] - arr[prev]
print(ans)


(n, k) = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
d = []
total = l[len(l) - 1] - l[0]
for i in range(len(l) - 1):
	diff = l[i + 1] - l[i]
	d.append(diff)
d.sort(reverse=True)
for i in range(k - 1):
	total -= d[i]
print(total)


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
diffs = []
for i in range(1, n):
	if arr[i] != arr[i - 1]:
		diffs.append(arr[i] - arr[i - 1])
diffs = list(reversed(sorted(diffs)))
ans = sum(diffs)
for i in range(min(len(diffs), k - 1)):
	ans -= diffs[i]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
diff = [a[i + 1] - a[i] for i in range(n - 1)]
diff.sort()
d = a[n - 1] - a[0]
for _ in range(k - 1):
	d -= diff.pop()
print(d)


from sys import stdin
(n, m) = map(int, stdin.readline().strip().split())
s = list(map(int, stdin.readline().strip().split()))
d = []
for i in range(1, n):
	d.append([s[i] - s[i - 1], i])
d.sort()
y = n - 1
x = [0, n]
for i in range(m - 1):
	x.append(d[-1][1])
	d.pop()
x.sort()
ans = 0
ind = 0
for i in range(1, len(x)):
	ans += s[x[i - 1]] - s[x[i] - 1]
print(abs(ans))


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
A = list(map(int, input().split()))
SUM = [0]
for a in A[::-1]:
	SUM.append(SUM[-1] + a)
SUM = SUM[::-1]
ANS = SUM[0]
ANS += sum(sorted(SUM[1:-1], reverse=True)[:k - 1])
print(ANS)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [0 for i in range(n)]
for i in range(n - 1, -1, -1):
	if i == n - 1:
		b[i] = a[i]
	else:
		b[i] = b[i + 1] + a[i]
ans = b[0]
b[1:] = sorted(b[1:])
k -= 1
for i in range(n - 1, -1, -1):
	if k == 0:
		break
	ans += b[i]
	k -= 1
print(ans)


(n, k) = map(int, input().split())
nums = list(map(int, input().split()))
suffixSum = [nums[-1]]
for i in nums[-2::-1]:
	suffixSum.append(suffixSum[-1] + i)
suffixSum = suffixSum[:-1]
suffixSum.sort(reverse=True)
ans = sum(nums)
ans += sum(suffixSum[:k - 1])
print(ans)


import sys
input = lambda : sys.stdin.readline().strip()
(n, k) = map(int, input().split())
ls = list(map(int, input().split()))
arr = []
for i in range(n - 1):
	arr.append(ls[i] - ls[i + 1])
arr.sort()
Sum = ls[-1] - ls[0]
for i in range(k - 1):
	Sum += arr[i]
print(Sum)


(n, k) = map(int, input().split())
x = list(map(int, input().split()))
y = []
for i in range(1, n):
	y.append(x[i] - x[i - 1])
y.sort()
print(sum(y[:n - k]))


(n, k) = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
res = s[n - 1] - s[0]
v = []
for i in range(1, n):
	v.append(s[i - 1] - s[i])
v.sort()
res += sum(v[:k - 1])
print(res)


(n, k) = [int(x) for x in input().split()]
a = list(map(int, input().split()))
if n == k:
	print(0)
	exit()
m = []
for i in range(n - 1):
	m.append([i, a[i + 1] - a[i]])
m.sort(key=lambda x: x[1])
m.reverse()
m = m[:k - 1]
m.sort(key=lambda x: x[0])
i = 0
j = 0
suma = 0
while k - 1:
	idx = m[i][0]
	mina = a[j]
	maxa = a[j + (idx - j)]
	suma += maxa - mina
	j = idx + 1
	k -= 1
	i += 1
suma += a[n - 1] - a[j]
print(suma)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
d = []
for i in range(n - 1):
	d.append(a[i + 1] - a[i])
d.sort(reverse=True)
print(sum(d[k - 1:]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
p = []
for i in range(1, len(a)):
	p.append(a[i - 1] - a[i])
p.sort()
ans = a[n - 1] - a[0]
for i in range(0, k - 1):
	ans += p[i]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
diff = []
arr = []
for i in range(0, n - 1):
	diff.append(a[i + 1] - a[i])
	arr.append([a[i + 1] - a[i], i])
arr.sort()
ind = []
i = 2
for i in range(k - 1):
	ind.append(arr[n - i - 2][1])
ind.sort()
ans = 0
ini = 0
for i in range(k - 1):
	ans += a[ind[i]] - a[ini]
	ini = ind[i] + 1
ans += a[-1] - a[ini]
print(ans)


n = input()
m = list(map(int, n.split(' ')))
sum = 0
store = []
arr = []
array = input()
arr = list(map(int, array.split()))
for i in range(m[0] - 1, -1, -1):
	sum = sum + arr[i]
	if i > 0:
		store.append(sum)
store.sort()
store = store[::-1]
ans = sum
for j in range(m[1] - 1):
	ans = ans + store[j]
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
tot = a[-1] - a[0]
n -= 1
k -= 1
for i in range(n):
	a[i] = a[i + 1] - a[i]
a.sort(reverse=1)
for i in range(1, k + 1):
	tot -= a[i]
print(tot)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = [0 for i in range(n)]
for i in range(n - 1, -1, -1):
	s[i] = a[i] if i == n - 1 else a[i] + s[i + 1]
s0 = s[0]
s1 = s[1:]
s1.sort()
res = 0
for i in range(n - 2, n - k - 1, -1):
	res += s1[i]
print(res + s0)


(n, k) = map(int, input().split())
li = list(map(int, input().split()))
z = li[n - 1] - li[0]
for i in range(n - 1):
	li[i] = li[i] - li[i + 1]
li.sort()
print(sum(li[:k - 1]) + z)


import sys, io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
suff = [0] * n
suff[-1] = a[-1]
for i in range(n - 2, -1, -1):
	suff[i] = suff[i + 1] + a[i]
ans = suff[0]
suff = suff[1:]
suff.sort(reverse=1)
ans += sum(suff[:k - 1])
print(ans)


(n, k) = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
diff = [0] * (n - 1)
if 1:
	for i in range(n - 1):
		diff[i] = A[i + 1] - A[i]
	ans = 0
	diff.sort()
	for i in range(len(diff) - (k - 1)):
		ans += diff[i]
	print(ans)


import io, sys
input = lambda f=io.StringIO(sys.stdin.buffer.read().decode()).readline: f().rstrip()
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
(n, k) = mi()
a = li()
d = [a[i + 1] - a[i] for i in range(n - 1)]
ans = sum(sorted(d)[:n - 1 - (k - 1)])
print(ans)


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if n == k:
	print(0)
	sys.exit()
cost = []
for i in range(n - 1):
	cost.append((a[i + 1] - a[i], i, i + 1))
cost.sort(key=lambda t: t[0], reverse=True)
cost = cost[:k - 1]
cost = sorted(((f, s) for (_, f, s) in cost))
res = 0
lp = 0
for (f, s) in cost:
	res += a[f] - a[lp]
	lp = s
res += a[-1] - a[lp]
print(res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
diff = []
for i in range(n - 1):
	diff.append(a[i + 1] - a[i])
ans = a[n - 1] - a[0]
diff.sort()
for i in range(k - 1):
	ans -= diff.pop()
print(ans)


from sys import stdin, stdout
nmbr = lambda : int(input())
lst = lambda : list(map(int, input().split()))
for _ in range(1):
	(n, k) = lst()
	a = lst()
	ans = a[-1] - a[0]
	l = []
	for i in range(1, n):
		l += [a[i - 1] - a[i]]
	l.sort()
	print(ans + sum(l[:k - 1]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if n == 1 or k == n:
	print(0)
elif k == 1:
	print(a[n - 1] - a[0])
else:
	b = [a[i + 1] - a[i] for i in range(n - 1)]
	b.sort(reverse=True)
	print(sum(b[k - 1:]))


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
vals = [A[i - 1] - A[i] for i in range(1, N)]
vals.sort()
print(A[-1] - A[0] + sum(vals[:K - 1]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [0 for l in range(n)]
for l in range(1, n):
	b[l] = a[l] - a[l - 1]
print(sum(sorted(b)[:n - k + 1]))


import sys
cin = lambda : map(int, sys.stdin.readline().split())
(n, k) = cin()
a = list(cin())
print(sum(sorted((y - x for (x, y) in zip(a, a[1:])))[:n - k]))


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
b = list(map(int, input().split()))
a = []
for j in range(n - 1):
	a.append(b[j + 1] - b[j])
a.sort(reverse=True)
q = a[:k - 1]
p = sum(q)
print(max(b) - b[0] - p)


(n, k) = map(int, input().split())
nl = list(map(int, input().split()))
b = []
for i in range(1, n):
	b.append(nl[i] - nl[i - 1])
b.sort()
print(sum(b[:n - k]))


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
d = sorted([a - b for (a, b) in zip(A[1:], A)])
if k == 1:
	ans = A[-1] - A[0]
else:
	ans = A[-1] - A[0] - sum(d[1 - k:])
print(ans)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions
from collections import deque, defaultdict, OrderedDict
from fractions import Fraction
from decimal import Decimal

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(1):
		(n, k) = ria()
		a = ria()
		ans = a[-1] - a[0]
		z = []
		for i in range(n - 1):
			z.append(a[i] - a[i + 1])
		z = sorted(z)
		for i in range(k - 1):
			ans += z[i]
		print(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from heapq import *
(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
dif = [a[i + 1] - a[i] for i in range(n - 1)]
dif.append(0)
ans = sum(dif)
heap = []
for i in dif:
	heappush(heap, -i)
for _ in range(k - 1):
	ans -= -heappop(heap)
print(ans)


(n, k) = tuple(map(int, input().split()))
a = list(map(int, input().split()))
diffs = []
for i in range(1, n):
	diffs.append(a[i - 1] - a[i])
diffs.sort()
ans = a[-1] - a[0]
for i in range(k - 1):
	ans += diffs[i]
print(ans)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
(n, k) = iia()
arr = iia()
adj_diff = []
for i in range(1, n):
	adj_diff.append(arr[i] - arr[i - 1])
adj_diff.sort()
print(sum(adj_diff[:n - k]))


import array
l = input().split(' ')
(lenArr, k) = (int(l[0]), int(l[1]))
arr = list(map(int, input().strip().split(' ')))
diff = []
for i in range(lenArr - 1):
	diff.append(arr[i] - arr[i + 1])
diff.sort()
score = arr[lenArr - 1] - arr[0]
for i in range(k - 1):
	score += diff[i]
print(score)


import copy

def coffee_problem():
	coffee_num_list = []
	(cup_num, page_num) = input().split(' ')
	coffee_num_per_cup = input().split(' ')
	cup_num = eval(cup_num)
	page_num = eval(page_num)
	for cup_idx in range(cup_num):
		coffee_num_list.append(eval(coffee_num_per_cup[cup_idx]))
	coffee_num_list.sort(reverse=True)
	if sum(coffee_num_list) < page_num:
		print(-1)
		return
	for i in range(1, cup_num + 1):
		done_page_num = 0
		for j in range(cup_num):
			done_page_num += max(coffee_num_list[j] - j // i, 0)
			if done_page_num >= page_num:
				print(i)
				return

def water_problem():
	query_num = eval(input())
	output_buffer = []
	for i in range(query_num):
		(water_liter, price1liter, price2liter) = input().split(' ')
		(water_liter, price1liter, price2liter) = (eval(water_liter), eval(price1liter), eval(price2liter))
		if price2liter / 2 >= price1liter:
			(num_of_1liter, num_of_2liter) = (water_liter, 0)
		else:
			num_of_2liter = water_liter // 2
			num_of_1liter = water_liter % 2
		whole_price = num_of_1liter * price1liter + num_of_2liter * price2liter
		output_buffer.append(str(whole_price))
	for output in output_buffer:
		print(output)
	return

def grape_problem():
	(andrew, dmitry, michal) = input().split(' ')
	(andrew, dmitry, michal) = (eval(andrew), eval(dmitry), eval(michal))
	(green, purple, black) = input().split(' ')
	(green, purple, black) = (eval(green), eval(purple), eval(black))
	if green < andrew:
		print('NO')
		return
	green = green - andrew
	if green + purple < dmitry:
		print('NO')
		return
	green_and_purple = green + purple - dmitry
	if green_and_purple + black < michal:
		print('NO')
		return
	print('YES')
	return

def one_point_problem(l1, r1, l2, r2):
	for answer1 in range(l1, r1 + 1):
		for answer2 in range(l2, r2 + 1):
			if answer1 != answer2:
				print(str(answer1) + ' ' + str(answer2))
				return

def point_problem():
	query_num = eval(input())
	query_list = []
	for _ in range(query_num):
		(l1, r1, l2, r2) = input().split(' ')
		(l1, r1, l2, r2) = (eval(l1), eval(r1), eval(l2), eval(r2))
		query_list.append([l1, r1, l2, r2])
	for query in query_list:
		one_point_problem(query[0], query[1], query[2], query[3])
	return

def get_result(city_num, capacity):
	sum = 0
	for i in range(2, city_num - capacity + 1):
		sum += i
	return sum

def trip_problem():
	(city_num, capacity) = input().split(' ')
	(city_num, capacity) = (eval(city_num), eval(capacity))
	if city_num <= capacity + 1:
		min_cost = city_num - 1
	else:
		min_cost = capacity + get_result(city_num, capacity)
	print(min_cost)
	return

def split_problem():
	num = eval(input())
	print(num)
	for i in range(num):
		print('1 ', end='')
	print()
	return

def positive_problem():
	(pos_num, neg_num) = (0, 0)
	n = eval(input())
	a = input().split(' ')
	for i in range(len(a)):
		a[i] = eval(a[i])
	for i in range(len(a)):
		if a[i] > 0:
			pos_num += 1
		elif a[i] < 0:
			neg_num += 1
	if n % 2 == 0:
		p = n // 2
	else:
		p = n // 2 + 1
	if pos_num >= p or neg_num >= p:
		if pos_num >= p:
			print('1')
		elif neg_num >= p and pos_num < p:
			print('-1')
	else:
		print('0')
	return

def sasha_problem():
	max_num = 110
	count = []
	n = eval(input())
	sum = 0
	answer = 0
	input_num = input().split(' ')
	for i in range(max_num):
		count.append(0)
	for i in range(len(input_num)):
		input_num[i] = eval(input_num[i])
		sum += input_num[i]
		count[input_num[i]] += 1
	for i in range(1, 101):
		for j in range(i + 1, 101):
			for k in range(2, 101):
				if count[i] and count[j] and (j % k == 0):
					answer = max(answer, int(j - j / k - (i * k - i)))
	answer = sum - answer
	print(answer)
	return

def football_problem():
	n = eval(input())
	answer = 1
	(a, b) = (0, 0)
	while n > 0:
		n -= 1
		(x, y) = input().split(' ')
		(x, y) = (eval(x), eval(y))
		if x == a and y == b:
			continue
		answer += max(0, min(x, y) - max(a, b) + 1)
		if a == b:
			answer -= 1
		(a, b) = (x, y)
	print(answer)
	return

def candy_problem():
	n = eval(input())
	input_list = input().split(' ')
	input_list.extend(['0', '0', '0'])
	for (i, _) in enumerate(input_list):
		input_list[i] = eval(input_list[i])
	(l2r, r2l) = (copy.deepcopy(input_list), copy.deepcopy(input_list))
	for i in range(n):
		if i >= 2:
			l2r[i] = input_list[i] + l2r[i - 2]
		else:
			l2r[i] = input_list[i]
	for i in range(n - 1, -1, -1):
		r2l[i] = input_list[i] + r2l[i + 2]
	answer = 0
	for i in range(n):
		(a, b) = (0, 0)
		if i >= 2:
			a = l2r[i - 2]
			b = l2r[i - 1]
		elif i == 1:
			b = l2r[0]
		a += r2l[i + 1]
		b += r2l[i + 2]
		if a == b:
			answer += 1
	print(answer)
	return

def emote_problem():
	(xmax, imax, flag, sum) = (0, 0, 0, 0)
	(n, m, k) = input().split(' ')
	(n, m, k) = (int(n), int(m), int(k))
	input_list = input().split(' ')
	for (i, _) in enumerate(input_list):
		input_list[i] = int(input_list[i])
	for (i, _) in enumerate(input_list):
		if input_list[i] > xmax:
			imax = xmax
			xmax = input_list[i]
		elif input_list[i] > imax:
			imax = input_list[i]
	if xmax == imax:
		sum = m * xmax
	else:
		sum = int(m // (k + 1) * (k * xmax + imax) + m % (k + 1) * xmax)
	print(sum)
	return

def string_problem():
	string = input()
	same_num = 0
	s = []
	for i in range(len(string)):
		if len(s) != 0:
			if string[i] == s[-1]:
				same_num += 1
				s.pop(-1)
			else:
				s.append(string[i])
		else:
			s.append(string[i])
	if same_num % 2 == 0:
		print('No')
	else:
		print('Yes')
	return

def tape_problem():
	(n, m, k) = input().split(' ')
	(n, m, k) = (int(n), int(m), int(k))
	b = input().split(' ')
	b_t = [0]
	b_t.extend(b)
	b = b_t
	for (i, _) in enumerate(b):
		b[i] = int(b[i])
	c = copy.deepcopy(b)
	for i in range(1, n):
		c[i] = b[i + 1] - b[i] - 1
	c[-1] = 0
	c[1:] = sorted(c[1:], reverse=True)
	answer = b[n] - b[1] + 1
	for i in range(1, k):
		answer -= c[i]
	print(answer)
	return

def cake_problem():
	n = int(input())
	a = []
	for i in range(n + 1):
		a.append([-1, -1])
	l = input().split(' ')
	for i in range(len(l)):
		l[i] = int(l[i])
		b = l[i]
		if a[b - 1][0] == -1:
			a[b - 1][0] = i
		else:
			a[b - 1][1] = i
	(len1, len2) = (a[0][0], a[0][1])
	for i in range(1, n):
		len1 += abs(a[i][0] - a[i - 1][0])
		len2 += abs(a[i][1] - a[i - 1][1])
	print(len1 + len2)
	return

def superhero_problem():
	(n, k, m) = input().split(' ')
	tmp = input().split(' ')
	(n, k, m) = (int(n), int(k), int(m))
	sum = 0
	for (i, _) in enumerate(tmp):
		tmp[i] = int(tmp[i])
		sum += tmp[i]
	tmp = sorted(tmp)
	a = [0]
	a.extend(tmp)
	answer = (sum + min(n * k, m)) / n
	for i in range(1, n):
		op = m - i
		sum -= a[i]
		if op < 0:
			break
		answer = max(answer, (sum + min((n - i) * k, op)) / (n - i))
	print(answer)
	return

def discounts_problem():
	n = int(input())
	a = input().split(' ')
	for (i, _) in enumerate(a):
		a[i] = int(a[i])
	a = sorted(a)
	m = int(input())
	sum = 0
	for i in range(n):
		sum += a[i]
	b = input().split(' ')
	for (i, _) in enumerate(b):
		b[i] = int(b[i])
	for i in range(m):
		print(sum - a[n - b[i]])
	return

def computer_games_problem():
	(n, k) = input().split(' ')
	(n, k) = (int(n), int(k))
	answer = min(k - 1, n - k) + 3 * n
	print(answer)
	return

def womens_day_problem():
	(n, k) = input().split(' ')
	(n, k) = (int(n), int(k))
	b = input().split(' ')
	for (i, _) in enumerate(b):
		b[i] = int(b[i])
	a = []
	for i in range(k + 1):
		a.append(0)
	for i in range(n):
		a[b[i] % k] += 1
	cnt = a[0] // 2
	if k % 2 == 0:
		cnt += a[k // 2] // 2
	for i in range((k + 1) // 2):
		tmp = min(a[i], a[k - i])
		cnt += tmp
		a[i] -= tmp
		a[k - i] -= tmp
	print(2 * cnt)
	return

def letters_rearranging_problem():
	t = int(input())
	while t != 0:
		t -= 1
		s = input()
		new_s_list = sorted(s)
		new_s = ''
		for (i, _) in enumerate(new_s_list):
			new_s += new_s_list[i]
		if new_s[0] == new_s[-1]:
			print('-1')
		else:
			print(new_s)
	return

def teams_forming_problem():
	n = int(input())
	a = input().split(' ')
	for (i, _) in enumerate(a):
		a[i] = int(a[i])
	a = sorted(a)
	answer = 0
	for i in range(0, n, 2):
		answer += a[i + 1] - a[i]
	print(answer)
	return

def check(n, k, v):
	for i in range(1, n + 1):
		if k[i] <= 0 or k[i] > n:
			return 0
		v[k[i]] += 1
	for i in range(1, n + 1):
		if not v[i]:
			return 0
	return 1

def polycarp_restores_permutation_problem():
	maxn = int(600000.0 + 10)
	n = int(input())
	input_list = input().split(' ')
	for (i, _) in enumerate(input_list):
		input_list[i] = int(input_list[i])
	a = [0 for i in range(maxn)]
	b = [0 for i in range(maxn)]
	k = [0 for i in range(maxn)]
	v = [0 for i in range(maxn)]
	for i in range(1, n):
		b[i] = input_list[i - 1]
	sum = n * (n + 1) / 2
	for i in range(1, n):
		a[i] = a[i - 1] + b[i]
		sum -= a[i]
	k[1] = int(sum / n)
	for i in range(2, n + 1):
		k[i] = k[1] + a[i - 1]
	s = 0
	for i in range(1, n + 1):
		s += k[i]
	if not check(n, k, v):
		print(-1)
	else:
		for i in range(1, n + 1):
			print(str(k[i]) + ' ', end='')
	return

def problem_1141b():
	n = int(input())
	input_list = input().split(' ')
	for (i, _) in enumerate(input_list):
		input_list[i] = int(input_list[i])
	for _ in range(n):
		input_list.append(0)
	for i in range(n, 2 * n - 1):
		input_list[i] = input_list[i - n]
	count = 0
	answer = 0
	for i in range(2 * n):
		if input_list[i] == 1:
			count += 1
			answer = max(answer, count)
		else:
			count = 0
	print(answer)
	return

def problem_1136c():
	gi = lambda : list(map(int, input().strip().split()))
	(n, m) = gi()
	a_list = [gi() for _ in range(n)]
	b_list = [gi() for _ in range(n)]
	for k in range(m):
		a = sorted([a_list[j][k - j] for j in range(min(n, k + 1))])
		b = sorted([b_list[j][k - j] for j in range(min(n, k + 1))])
		if a != b:
			print('NO')
			return
	for k in range(m):
		a = sorted([a_list[-j - 1][j - 1 - k] for j in range(min(n, k + 1))])
		b = sorted([b_list[-j - 1][-k + j - 1] for j in range(min(n, k + 1))])
		if a != b:
			print('NO')
			return
	if n <= m:
		print('YES')
		return
	for k in range(n):
		a = sorted([a_list[k - j][j] for j in range(min(m, k + 1))])
		b = sorted([b_list[k - j][j] for j in range(min(m, k + 1))])
		if a != b:
			print('NO')
			return
	for k in range(n):
		a = sorted([a_list[-k - 1 + j][-j - 1] for j in range(min(m, k + 1))])
		b = sorted([b_list[-k - 1 + j][-j - 1] for j in range(min(m, k + 1))])
		if a != b:
			print('NO')
			return
	print('YES')
	return

def get_len(t, z):
	ori_len = len(t)
	length = 0
	i = 1
	while i < ori_len:
		if t[i] == t[length]:
			length += 1
			z[i] = length
			i += 1
		elif length != 0:
			length = z[length - 1]
		else:
			z[i] = 0
			i += 1
	return z[ori_len - 1]

def problem_1137b():
	maxn = int(1000000.0)
	s = input()
	t = input()
	(zs, os, zt, ot) = (0, 0, 0, 0)
	for i in range(len(s)):
		if s[i] == '0':
			zs += 1
		else:
			os += 1
	for i in range(len(t)):
		if t[i] == '0':
			zt += 1
		else:
			ot += 1
	if zt > zs or ot > os:
		print(s)
		return
	z = [0 for _ in range(maxn)]
	len_t = get_len(t, z)
	answer = t
	add = t[len_t:len(t)]
	(nz, no) = (0, 0)
	(currz, curro) = (zt, ot)
	for i in range(len(add)):
		if add[i] == '0':
			nz += 1
		else:
			no += 1
	while currz + nz <= zs and curro + no <= os:
		answer += add
		currz += nz
		curro += no
	for i in range(zs - currz):
		answer += '0'
	for i in range(os - curro):
		answer += '1'
	print(answer)
	return

def problem_1138b():
	n = int(input())
	c = input()
	a = input()
	(n0, c0, a0, b0) = (0, 0, 0, 0)
	for i in range(n):
		if c[i] == '0' and a[i] == '0':
			n0 += 1
		elif c[i] == '0' and a[i] == '1':
			a0 += 1
		elif c[i] == '1' and a[i] == '0':
			c0 += 1
		else:
			b0 += 1
	half_n = int(n / 2)
	for i in range(half_n + 1):
		if b0 > 2 * i:
			continue
		if a0 < i and c0 < i:
			if i - a0 + i - c0 == b0:
				em = half_n - i
				d1 = i - c0
				cc = i
				if em > n0:
					continue
				for i in range(n):
					if c[i] == '0' and a[i] == '0' and em:
						em -= 1
						print(str(i + 1) + ' ', end='')
					elif c[i] == '0' and a[i] == '1':
						continue
					elif c[i] == '1' and a[i] == '0' and cc:
						cc -= 1
						print(str(i + 1) + ' ', end='')
					elif c[i] == '1' and a[i] == '1' and d1:
						d1 -= 1
						print(str(i + 1) + ' ', end='')
				return
		elif c0 < i <= a0:
			d1 = b0 - i + c0
			d2 = a0 - i
			if i >= d1 >= 0:
				d5 = i - c0
				d3 = d2 + d1
				d4 = half_n - i - d3
				cc = i
				if d4 > n0 or d4 < 0:
					continue
				for i in range(n):
					if c[i] == '0' and a[i] == '0' and d4:
						d4 -= 1
						print(str(i + 1) + ' ', end='')
					elif c[i] == '0' and a[i] == '1' and d3:
						d3 -= 1
						print(str(i + 1) + ' ', end='')
					elif c[i] == '1' and a[i] == '0' and cc:
						cc -= 1
						print(str(i + 1) + ' ', end='')
					elif c[i] == '1' and a[i] == '1' and d5:
						d5 -= 1
						print(str(i + 1) + ' ', end='')
				return
		elif a0 < i <= c0:
			d1 = b0 - i + a0
			if 0 <= d1 <= i:
				cc = i - d1
				d2 = half_n - cc - d1
				if d2 > n0 or d2 < 0:
					continue
				for i in range(n):
					if c[i] == '0' and a[i] == '0' and d2:
						d2 -= 1
						print(str(i + 1) + ' ', end='')
					elif c[i] == '0' and a[i] == '1':
						continue
					elif c[i] == '1' and a[i] == '0' and cc:
						cc -= 1
						print(str(i + 1) + ' ', end='')
					elif c[i] == '1' and a[i] == '1' and d1:
						d1 -= 1
						print(str(i + 1) + ' ', end='')
				return
		else:
			d1 = int(b0 / 2)
			d2 = i - d1
			d3 = b0 - d1
			d4 = i - d3
			d5 = c0 - d2
			d6 = a0 - d4
			if d6 + d1 + d2 <= half_n and d3 + d4 + d5 <= half_n:
				d7 = half_n - d6 - d1 - d2
				if d7 > n0 or d2 < 0:
					continue
				for i in range(n):
					if c[i] == '0' and a[i] == '0' and d7:
						d7 -= 1
						print(str(i + 1) + ' ', end='')
					elif c[i] == '0' and a[i] == '1' and d6:
						d6 -= 1
						print(str(i + 1) + ' ', end='')
					elif c[i] == '1' and a[i] == '0' and d2:
						d2 -= 1
						print(str(i + 1) + ' ', end='')
					elif c[i] == '1' and a[i] == '1' and d1:
						d1 -= 1
						print(str(i + 1) + ' ', end='')
				return
	print(-1)
	return

def problem_1139b():
	n = int(input())
	a = input().split(' ')
	for (i, _) in enumerate(a):
		a[i] = int(a[i])
	mi = a[n - 1] - 1
	for i in range(n - 2, -1, -1):
		if a[i] < mi:
			mi = a[i] - 1
		else:
			a[i] = mi
			mi = max(mi - 1, 0)
	answer = 0
	for i in range(n):
		answer += a[i]
	print(answer)
	return

def problem_1132c():
	maxn = 5001
	lst = [0 for _ in range(maxn)]
	dp = [0 for _ in range(maxn)]
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	for i in range(1, n + 1):
		lst[i] = i + 1
	for i in range(1, m + 1):
		(l, r) = input().split(' ')
		(l, r) = (int(l), int(r))
		for j in range(l, r + 1):
			if lst[j] > l:
				lst[j] = l
	for k in range(1, m - 1):
		for i in range(n, 0, -1):
			tmp = dp[lst[i] - 1] + i - lst[i] + 1
			if tmp > dp[i]:
				dp[i] = tmp
		for i in range(1, n + 1):
			if dp[i - 1] > dp[i]:
				dp[i] = dp[i - 1]
	print(dp[n])
	return

def problem_1133c():
	nmax = 0
	n = int(input())
	a = input().split(' ')
	for (i, _) in enumerate(a):
		a[i] = int(a[i])
	a.sort()
	(i, j) = (0, 1)
	while i < n - 1 and j < n:
		if a[j] - a[j - 1] > 5:
			if j - 1 - i > nmax:
				nmax = j - 1 - i
			i = j
			j += 1
		elif a[j] - a[i] > 5:
			if j - 1 - i > nmax:
				nmax = j - 1 - i
			i += 1
			if i == j:
				j += 1
		else:
			j += 1
	if j - 1 - i > nmax:
		nmax = j - 1 - i
	print(nmax + 1)
	return

def problem_1197c():
	(n, k) = input().split(' ')
	a = input().split(' ')
	(n, k) = (int(n), int(k))
	da = []
	for (i, _) in enumerate(a):
		a[i] = int(_)
		if i != 0:
			da.append(a[i] - a[i - 1])
	da.sort(reverse=True)
	max_da = 0
	for i in range(k - 1):
		max_da += da[i]
	result = a[-1] - a[0] - max_da
	print(result)
	return None
problem_1197c()


(n, k) = map(int, input().split())
(a, s, Sum) = (list(map(int, input().split())), list(), 0)
for i in range(1, n):
	s.append(a[i] - a[i - 1])
s.sort()
for i in range(n - k):
	Sum += s[i]
print(Sum)


(n, k) = map(int, input().split(' '))
li = list(map(int, input().split(' ')))
mi = [li[i + 1] - li[i] for i in range(len(li) - 1)]
mi.sort()
print(sum(mi[:n - k]))


import math
from decimal import *
import random
mod = int(1000000000.0) + 7
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
vals = []
for i in range(1, n):
	vals.append(arr[i] - arr[i - 1])
vals = sorted(vals, reverse=True)
ans = arr[-1] - arr[0]
for i in range(k - 1):
	ans -= vals[i]
print(ans)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
v = []
for i in range(1, n):
	v.append(a[i - 1] - a[i])
v = sorted(v)
res = a[n - 1] - a[0]
for i in range(k - 1):
	res += v[i]
print(res)


(M, N) = map(int, input().split())
tree = []
numbers = input().split()
for x in range(M - 1):
	tree += [int(numbers[x + 1]) - int(numbers[x])]
tree = sorted(tree)
for x in range(N - 1):
	tree[M - 2 - x] = 0
print(sum(tree))


(n, k) = [int(w) for w in input().split()]
li = [int(w) for w in input().split()]
li1 = []
for i in range(1, n):
	ele = li[i] - li[i - 1]
	li1.append(ele)
li1.sort()
sum = 0
for i in range(0, n - k):
	sum = sum + li1[i]
print(sum)


(n, k) = [int(q) for q in input().split()]
l = [int(w) for w in input().split()]
l2 = []
answ = 0
for i in range(n - 1):
	l2.append(l[i] - l[i + 1])
l2 = sorted(l2)
for j in range(k - 1):
	answ += l2[j]
print(l[-1] - l[0] + answ)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, OrderedDict
import math
import heapq

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
(n, k) = listIn()
a = listIn()
arr = [a[0]] + [0] * (n - 1)
for i in range(1, n):
	arr[i] = arr[i - 1] + a[i]
max_cost = arr[n - 1] * k
b = sorted(arr[:n - 1])
for i in range(k - 1):
	max_cost -= b[i]
print(max_cost)


(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
min_cost = a[-1] - a[0]
for i in range(n - 1):
	a[i] = a[i + 1] - a[i]
a[n - 1] = -a[n - 1]
a.sort()
for i in range(k - 1):
	min_cost -= a[n - 1 - i]
print(min_cost)


import sys
(n, k) = list(map(int, sys.stdin.readline().strip().split()))
a = list(map(int, sys.stdin.readline().strip().split()))
b = [0] * (n - 1)
for i in range(0, n - 1):
	b[i] = a[i + 1] - a[i]
b.sort(reverse=True)
print(a[n - 1] - a[0] - sum(b[0:k - 1]))


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n, k) = I()
a = I()
z = [a[0]]
for i in a[1:]:
	if i != z[-1]:
		z.append(i)
n = len(z)
m = n - k
a = z
ans = MOD
z = []
if k >= n:
	print(0)
	exit()
for i in range(n - 1):
	z.append(a[i + 1] - a[i])
z.sort(reverse=True)
print(a[-1] - a[0] - sum(z[:k - 1]))


(n, k) = map(int, input().split())
l = [int(x) for x in input().split()]
if len(l) == 1:
	print(0)
else:
	ans = l[-1] - l[0]
	m = []
	for i in range(1, n):
		m.append(l[i] - l[i - 1])
	m.sort(reverse=True)
	for i in range(k - 1):
		ans -= m[i]
	print(ans)


(n, k) = map(int, input().split())
x = list(map(int, input().split()))
b = sorted((v - u for (u, v) in zip(x, x[1:])), reverse=True)
print(sum(b[k - 1:]))


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
b = []
for i in range(1, n):
	b.append(a[i - 1] - a[i])
b.sort()
ans = a[n - 1] - a[0]
for i in range(k - 1):
	ans += b[i]
print(ans)


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
diff = []
for i in range(n - 1):
	diff.append(a[i + 1] - a[i])
diff = sorted(diff)
res = 0
for i in range(n - k):
	res += diff[i]
print(res)


import sys
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
(n, k) = intInp()
arr = intInp()
diff = []
for i in range(n - 1):
	diff.append(arr[i + 1] - arr[i])
diff.sort()
print(sum(diff[0:n - (k - 1) - 1]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
difflist = []
for i in range(n - 1):
	difflist.append(a[i + 1] - a[i])
difflist.sort()
for i in range(k - 1):
	difflist.pop()
ans = sum(difflist)
print(ans)


from sys import stdin

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
(n, k) = minput()
a = linput()
a.sort()
diff = []
for i in range(n - 1):
	diff.append(a[i + 1] - a[i])
diff.sort()
print(sum(diff[:n - (k - 1) - 1]))


from sys import stdin, stdout
(N, K) = [int(x) for x in stdin.readline().split()]
arr = [int(x) for x in stdin.readline().split()]
if K == 1:
	print(sum(arr))
	quit()
cum = [0] * N
s = 0
for i in range(N - 1, -1, -1):
	s += arr[i]
	cum[i] = s
tmp = cum[0]
A = sorted(cum[1:], reverse=True)
res = tmp
for i in range(K - 1):
	res += A[i]
print(res)


(n, k) = map(int, input().split())
A = [int(i) for i in input().split()]
A = A[::-1]
if n == k:
	print(0)
else:
	diff = [0] * (n - 1)
	for i in range(1, n):
		diff[i - 1] = A[i - 1] - A[i]
	diff.sort()
	rem = n - k
	sumi = 0
	for i in range(rem):
		sumi += diff[i]
	print(sumi)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
prefix_sum = [0]
for t in a:
	prefix_sum.append(prefix_sum[-1] + t)
sk = prefix_sum[-1]
prefix_sum = sorted(prefix_sum[1:-1])
print(k * sk - sum(prefix_sum[:k - 1]))


(N, K) = input().split()
N = int(N)
K = int(K)
A = input().split()
A = list(map(int, A))
diff = [A[i + 1] - A[i] for i in range(N - 1)]
diff = sorted(diff, reverse=True)
print(A[-1] - A[0] - sum(diff[:K - 1]))


import sys, math

def read_int():
	return int(sys.stdin.readline().strip())

def read_int_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def read_string():
	return sys.stdin.readline().strip()

def read_string_list(delim=' '):
	return sys.stdin.readline().strip().split(delim)
(n, k) = read_int_list()
arr = read_int_list()
for i in range(n - 2, -1, -1):
	arr[i] += arr[i + 1]
ans = arr[0]
arr.pop(0)
arr.sort(reverse=True)
ans += sum(arr[:k - 1])
print(ans)


from operator import itemgetter
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cnt = k - 1
li = [[0, 0] for i in range(n - 1)]
for i in range(n - 1):
	li[i][0] = a[i + 1] - a[i]
	li[i][1] = i
li = sorted(li, reverse=True)
li = li[0:cnt]
li = sorted(li, key=itemgetter(1))
s = 0
ans = 0
for i in range(len(li)):
	ans += a[li[i][1]] - a[s]
	s = li[i][1] + 1
ans += a[-1] - a[s]
print(ans)


(n, k) = map(int, input().split())
dat = list(map(int, input().split()))
d = []
total = dat[-1] - dat[0]
for i in range(1, n):
	d.append(dat[i] - dat[i - 1])
d.sort()
total = total - sum(d[n - k:])
print(total)


import sys
(n, k) = map(int, sys.stdin.readline().strip().split())
a = [int(x) for x in sys.stdin.readline().strip().split()]
if n == k:
	print(0)
elif k == 1:
	print(a[-1] - a[0])
else:
	d = [0] * (n - 1)
	for pos in range(n - 1):
		d[pos] = a[pos + 1] - a[pos]
	d.sort()
	print(sum(d[:-k + 1]))


(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
diff = []
for i in range(1, n):
	diff.append(A[i] - A[i - 1])
diff.sort(reverse=True)
cost = 0
for i in range(k - 1):
	cost += diff[i]
ans = A[n - 1] - A[0] - cost
print(ans)


(n, k) = list(map(int, input().split()))
nums = list(map(int, input().split()))
if n == k:
	print(0)
	raise SystemExit
if k == 1:
	print(nums[n - 1] - nums[0])
	raise SystemExit
dif = []
for i in range(n - 1):
	dif.append(nums[i + 1] - nums[i])
dif.sort()
sum = 0
for i in range(n - k):
	sum += dif[i]
print(sum)


(n, k) = map(int, input().split(' '))
vs = list(map(int, input().split(' ')))
dfs = [vs[i] - vs[i - 1] for i in range(1, len(vs))]
sums = sum(dfs)
save = sum(list(sorted(dfs))[-(k - 1):])
if k == 1:
	save = 0
print(sums - save)


class Read:

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def main():
	(n, k) = Read.list_int()
	a = list(set(Read.list_int()))
	a.sort()
	b = []
	for i in range(1, len(a)):
		b.append(a[i] - a[i - 1])
	b.sort()
	res = 0
	for i in range(0, len(b) - k + 1):
		res += b[i]
	print(res)
t = 1
for j in range(t):
	main()


(n, j) = input().split()
l = list(map(int, input().split()))
t = []
for i in range(1, int(n)):
	t.append(l[i] - l[i - 1])
t.sort()
print(sum(t[:int(n) - int(j)]))


(n, k) = map(int, input().split())
u = list(map(int, input().split()))
d = [0] * (n - 1)
for i in range(1, n):
	d[i - 1] = u[i] - u[i - 1]
d.sort()
s = sum(d)
for i in range(k - 1):
	s -= d[n - i - 2]
print(s)


from sys import stdin
input = stdin.readline
(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
if n == k:
	print(0)
else:
	d = sorted([a[i] - a[i - 1] for i in range(1, n)])
	print(sum(d[:n - k]))


(n, k) = map(int, input().strip().split(' '))
lst = list(map(int, input().strip().split(' ')))
l = []
if k == n:
	print(0)
elif k == 1:
	print(max(lst) - min(lst))
else:
	for i in range(1, n):
		l.append(lst[i] - lst[i - 1])
	l.sort(reverse=True)
	s = sum(l)
	for j in range(k - 1):
		s -= l[j]
	print(s)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = [0] * (n - 1)
s = SegmentTree(l)
for i in range(1, n):
	a[i - 1] = s.query(i, n - 1)
a.sort(reverse=True)
print(sum(a[:k - 1]) + sum(l))


def func(n, k, arr):
	if k == 1:
		return arr[-1] - arr[0]
	arr2 = []
	for i in range(n - 1):
		arr2.append((i, arr[i + 1] - arr[i]))
	arr2.sort(key=lambda x: (-x[1], -x[0]))
	mark = [0 for i in range(n)]
	for i in range(k - 1):
		mark[arr2[i][0]] = 1
	ans = 0
	start = 0
	for i in range(n):
		if mark[i] == 1:
			ans += arr[i] - arr[start]
			start = i + 1
	ans += arr[n - 1] - arr[start]
	return ans
a = [int(i) for i in input().split()]
n = a[0]
k = a[1]
arr = [int(i) for i in input().split()]
print(func(n, k, arr))


(N, K) = map(int, input().split())
A = [int(a) for a in input().split()]
B = [0] * N
B[N - 1] = A[N - 1]
for i in range(N - 1)[::-1]:
	B[i] = B[i + 1] + A[i]
print(sum(sorted(B[1:])[::-1][:K - 1]) + B[0])


(n, k) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
l.sort()
if k == 1 or n == 1:
	print(l[-1] - l[0])
else:
	l1 = []
	for i in range(n - 1):
		l1.append(l[i + 1] - l[i])
	l1.sort(reverse=True)
	sum = 0
	for i in range(k - 1):
		sum += l1[i]
	print(l[-1] - l[0] - sum)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
i = 1
b = []
while i < n:
	b.append(a[i] - a[i - 1])
	i += 1
b.sort()
j = len(b) - 1
i = 0
s = 0
while i < k - 1:
	s += b[j]
	j -= 1
	i += 1
print(a[n - 1] - a[0] - s)


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	ans = a[n - 1] - a[0]
	yoyo = []
	for x in range(1, n):
		yoyo.append(-a[x] + a[x - 1])
	print(ans + sum(sorted(yoyo)[:k - 1]))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = []
l = a[-1] - a[0]
for i in range(len(a) - 1):
	c.append(a[i] - a[i + 1])
c = sorted(c)
for i in range(k - 1):
	l += c[i]
print(l)


import math
import os
import random
import re
import sys
(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
gap = []
for i in range(1, len(ar)):
	gap.append(ar[i] - ar[i - 1])
gap = sorted(gap)
ans = 0
for i in range(0, n - k):
	ans += gap[i]
print(ans)


(N, K) = (int(x) for x in input().split(' ') if len(x) > 0)
vals = [int(x) for x in input().split(' ') if len(x) > 0]
if K > N:
	print(0)
else:
	costs = []
	for n in range(0, N - 1):
		costs.append(vals[n] - vals[n + 1])
	costs = sorted(costs)
	print(vals[N - 1] - vals[0] + sum(costs[0:K - 1]))


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
B = []
for i in range(n - 1):
	B.append([A[i + 1] - A[i], i])
B.sort(reverse=True)
C = []
for i in range(k - 1):
	C.append(B[i][1])
C.sort()
ans = 0
mi = 10 ** 9
ma = -10 ** 9
u = 0
for i in range(n):
	mi = min(mi, A[i])
	ma = max(ma, A[i])
	if u < len(C) and i == C[u]:
		ans += ma - mi
		mi = 10 ** 9
		ma = -10 ** 9
		u += 1
print(ans + ma - mi)


import sys
(n, k) = map(int, sys.stdin.readline().split())
l = list(map(int, sys.stdin.readline().split()))
cost = l[n - 1] - l[0]
if k == 1:
	print(cost)
else:
	diff = [0 for _ in range(n - 1)]
	for i in range(n - 1):
		diff[i] = l[i + 1] - l[i]
	diff = sorted(diff)
	diff.reverse()
	print(cost - sum(diff[:k - 1]))


def mp():
	return map(int, input().split())
(n, k) = mp()
a = list(mp())
b = [0] * (n - 1)
for i in range(n - 1):
	b[i] = a[i + 1] - a[i]
k -= 1
b.sort(reverse=True)
print(sum(b[k:]))


(n, k) = tuple(map(int, input().strip().split()))
arr = tuple(map(int, input().strip().split()))
diff = []
for i in range(n - 1):
	diff.append(arr[i + 1] - arr[i])
diff.sort(reverse=True)
print(sum(diff[k - 1:]))


(n, k) = map(int, input().split())
s = [int(x) for x in input().split()]
pos = [0] * (n + 1)
L = []
for i in range(0, len(s) - 1):
	L.append(s[i] - s[i + 1])
L.sort()
tot = s[-1] - s[0]
for i in range(k - 1):
	tot += L[i]
print(tot)


(n, k) = [int(w) for w in input().split()]
a = [int(w) for w in input().split()]
b = [y - x for (x, y) in zip(a, a[1:])]
b.sort()
print(a[-1] - a[0] - sum(b[n - k:]))


a = input('')
n = 0
k = 0
for i in a.split(' '):
	if n == 0:
		n = int(i)
		j = 1
	else:
		k = int(i)
b = input('')
l = []
ans = 0
s = int(b.split(' ')[0])
for i in b.split(' '):
	if ans == 1:
		l.append(int(i) - s)
		s = int(i)
	else:
		ans = 1
l.sort()
ans = sum(l[0:n - k])
print(ans)


from sys import stdin, stdout, exit
(n, k) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
difs = [a[i + 1] - a[i] for i in range(n - 1)]
difs.sort(reverse=True)
ans = max(a) - min(a)
ans -= sum(difs[:k - 1])
stdout.write(str(ans) + '\n')


import io, os
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
summ = 0
v = []
for i in range(n - 1, -1, -1):
	summ += a[i]
	if i > 0:
		v.append(summ)
ans = summ
v.sort(reverse=True)
for i in range(k - 1):
	ans += v[i]
print(ans)


(n, k) = map(int, input().split(' '))
a_list = list(map(int, input().split(' ')))
diffs = [[i, a_list[i + 1] - a_list[i]] for i in range(n - 1)]
diffs = sorted(diffs, key=lambda x: -x[1])
split_indexs = [diffs[i][0] for i in range(k - 1)]
out = 0
first_i = 0
for end_i in split_indexs:
	out += a_list[end_i] - a_list[first_i]
	first_i = end_i + 1
out += a_list[-1] - a_list[first_i]
print(out)


li = input().split()
n = int(li[0])
k = int(li[1])
a = input().split()
for i in range(n):
	a[i] = int(a[i])
for i in range(n - 2, -1, -1):
	a[i] += a[i + 1]
sa = sorted(a[1:])
ans = a[0]
for i in range(k - 1):
	ans += sa[n - 2 - i]
print(ans)


(n, k) = map(int, input().split(' '))
y = list(map(int, input().split()))
c = []
j = 1
while j < n:
	c.append(y[j] - y[j - 1])
	j += 1
c = sorted(c)
if n == k:
	print(0)
else:
	print(sum(c[:n - 1 - (k - 1)]))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
diff = []
for i in range(n - 1):
	diff.append(abs(l[i] - l[i + 1]))
diff.sort()
print(sum(diff[0:n - k]))


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = [a[-1]]
for i in range(n - 2, -1, -1):
	s.append(s[-1] + a[i])
(a, s) = (s[-1], s[:-1])
s.sort()
if k > 1:
	print(a + sum(s[1 - k:]))
else:
	print(a)


(n, k) = map(int, input().split())
s = [int(i) for i in input().split()]
sum = []
total = s[-1] - s[0]
for i in range(len(s) - 1):
	sum.append(s[i + 1] - s[i])
sorted_sum = sorted(sum, reverse=True)
for i in range(k - 1):
	total -= sorted_sum[i]
print(total)


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.readline
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	B = [A[i + 1] - A[i] for i in range(N - 1)]
	B.sort()
	ans = A[-1] - A[0]
	for _ in range(K - 1):
		ans -= B.pop()
	print(ans)
main()


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def reVal(num):
	if num >= 0 and num <= 9:
		return chr(num + ord('0'))
	else:
		return chr(num - 10 + ord('A'))

def strev(str):
	len = len(str)
	for i in range(int(len / 2)):
		temp = str[i]
		str[i] = str[len - i - 1]
		str[len - i - 1] = temp

def fromDeci(res, base, inputNum):
	index = 0
	while inputNum > 0:
		res += reVal(inputNum % base)
		inputNum = int(inputNum / base)
	res = res[::-1]
	return res

def norm(s, l):
	tba = '0' * (l - len(s))
	return tba + s
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
a = l[-1] - l[0]
diff = []
for i in range(1, n):
	diff.append(l[i - 1] - l[i])
diff.sort()
print(a + sum(diff[:k - 1]))


(n, k) = map(int, input().split())
num = list(map(int, input().split()))
h = sorted([num[i] - num[i - 1] for i in range(1, n)])
(ans, p) = (num[n - 1] - num[0], n - 2)
while k >= 2:
	k -= 1
	ans -= h[p]
	p -= 1
print(ans)


(n, k) = map(int, input().split())
A = [int(x) for x in input().split()]
B = []
for i in range(1, n):
	B.append([A[i] - A[i - 1], i])
B.sort(reverse=True)
B = [[0, n]] + B[:k - 1] + [[0, 0]]
S = 0
for i in range(1, k + 1):
	Min = A[B[i][1]]
	Max = A[B[i - 1][1] - 1]
	S += Max - Min
print(S)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
res = a[n - 1] - a[0]
v = []
for i in range(1, n):
	v.append(a[i - 1] - a[i])
v.sort()
for i in range(0, k - 1):
	res += v[i]
print(res)


from operator import itemgetter
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k == n:
	print(0)
elif k == 1:
	print(a[-1] - a[0])
else:
	jumps = [0] * n
	jumps[0] = (0, 0)
	for i in range(1, n):
		jumps[i] = (a[i] - a[i - 1], i)
	j = sorted(jumps, key=itemgetter(0))
	jj = sorted(j[-k + 1:], key=itemgetter(1))
	ans = 0
	s = 0
	for (_, i) in jj:
		ans += a[i - 1] - a[s]
		s = i
	ans += a[-1] - a[s]
	print(ans)


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
(N, K) = map(int, input().split())
L = list(map(int, input().split()))
L_acc = [l2 - l1 for (l1, l2) in zip(L, L[1:])]
L_acc = sorted(L_acc, reverse=True)
ans = sum(L_acc)
for i in range(K - 1):
	ans -= L_acc[i]
print(ans)


(n, m) = map(int, input().split())
ar = list(map(int, input().split()))
p = []
for i in range(1, n):
	p.append(ar[i] - ar[i - 1])
p.sort()
print(sum(p[:n - m]))


import sys
input = sys.stdin.readline
(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
acc = [a.pop()]
while a:
	acc.append(a.pop() + acc[-1])
s1 = acc.pop()
acc.sort()
ans = sum(acc[n - k:]) + s1
print(ans)


import math
import sys
import collections

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))
(n, k) = mi()
d = li()
dif = []
for i in range(1, n):
	dif.append([d[i] - d[i - 1], i - 1, i])
dif.sort(reverse=True)
res = 0
l = [0, n - 1]
for i in range(k - 1):
	l.append(dif[i][1])
	l.append(dif[i][2])
l.sort()
for i in range(1, len(l), 2):
	res += d[l[i]] - d[l[i - 1]]
print(res)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
presum = [None] * n
presum[0] = a[0]
for i in range(1, len(a)):
	presum[i] = presum[i - 1] + a[i]
ans = presum[n - 1] * k
presum.pop()
presum.sort()
for i in range(0, k - 1):
	ans -= presum[i]
print(ans)


(n, k) = map(int, input().split())
c = list(map(int, input().split()))
dif = []
for i in range(1, n):
	dif.append(c[i] - c[i - 1])
dif.sort()
ans = 0
for i in range(n - k):
	ans += dif[i]
print(ans)


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = self.next_line()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_line(self):
		return sys.stdin.readline().split()

	def next_ints(self):
		return [int(x) for x in sys.stdin.readline().split()]

	def next_int(self):
		return int(self.next())

	def solve(self):
		(n, k) = self.next_ints()
		x = self.next_ints()
		ss = []
		s = 0
		for a in x[::-1]:
			s += a
			ss.append(s)
		ss = sorted(ss[:-1], reverse=True)
		print(s + sum(ss[:k - 1]))
Main().solve()


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
if n == k:
	print(0)
elif k == n - 1:
	m = arr[-1] - arr[0]
	for i in range(1, n):
		if arr[i] - arr[i - 1] < m:
			m = arr[i] - arr[i - 1]
	print(m)
elif k == 1:
	print(arr[-1] - arr[0])
else:
	p = [0] * (n - 1)
	for i in range(1, n):
		p[i - 1] = arr[i] - arr[i - 1]
	p.sort()
	s = 0
	for i in range(n - k):
		s += p[i]
	print(s)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
else:
	p = [a[-1]] + [0] * (n - 2)
	for i in range(n - 2):
		p[i + 1] = p[i] + a[-i - 2]
	j = p[-1] + a[0]
	p.sort(reverse=True)
	print(j + sum(p[:k - 1]))


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
c = l[a - 1] - l[0]
d = [0] * (a - 1)
for i in range(1, a):
	d[i - 1] = l[i - 1] - l[i]
d.sort()
c += sum(d[:b - 1])
print(c)


import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
	return int(input())

def getList():
	return list(map(int, input().split()))
import math
(n, k) = getList()
nums = getList()
diff = []
for (i, j) in zip(nums, nums[1:]):
	diff.append(j - i)
diff.sort()
print(sum(diff[:n - k]))


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
c = a[-1] - a[0]
x = []
for i in range(len(a) - 1):
	x.append(a[i] - a[i + 1])
x.sort()
for i in range(k - 1):
	c += x[i]
print(c)


import sys
(n, k) = map(int, input().split(' '))
if n == k:
	print(0)
	sys.exit(0)
num = [int(x) for x in input().split()]
if k == 1:
	print(num[len(num) - 1] - num[0])
	sys.exit(0)
l = []
for i in range(len(num) - 1):
	l.append(num[i + 1] - num[i])
l.sort()
sum = 0
for i in range(n - k):
	sum += l[i]
print(sum)


input_func = lambda : [int(i) for i in input().split()]
(n, k) = input_func()
a = input_func()
a = sorted([a[i + 1] - a[i] for i in range(n - 1)])
print(sum(a[:n - k]))


inputs = input().split(' ')
n = int(inputs[0])
k = int(inputs[1])
nums = input().split(' ')
arr = []
sum = 0
for x in nums:
	arr.append(int(x))
diff = []
for i in range(n - 1):
	diff.append(arr[i + 1] - arr[i])
	sum += arr[i + 1] - arr[i]
diff.sort(reverse=True)
sumtobesub = 0
for i in range(k - 1):
	sumtobesub += diff[i]
print(sum - sumtobesub)


import sys
import math

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]
(n, k) = read_int_line()
a = read_int_line()
b = [0] * (n - 1)
for i in range(1, n):
	b[i - 1] = a[i - 1] - a[i]
b.sort()
ans = a[n - 1] - a[0]
for i in range(k - 1):
	ans += b[i]
print(ans)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
dif = []
for i in range(n - 1):
	dif.append(arr[i + 1] - arr[i])
dif = sorted(dif, reverse=True)
ans = arr[n - 1] - arr[0]
for i in range(k - 1):
	ans -= dif[i]
print(ans)


import sys, math, queue
MOD = 998244353
sys.setrecursionlimit(1000000)
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted([a[i] - a[i - 1] for i in range(1, n)])
print(sum(a[:n - k]))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
	print(0)
	exit()
if k == 1:
	print(a[-1] - a[0])
	exit()
diffs = []
for i in range(n - 1):
	diffs.append(a[i + 1] - a[i])
diffs = sorted(diffs)
print(sum(diffs[:-(k - 1)]))


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	(N, K) = getInts()
	A = getInts()
	suffs = [0]
	for i in range(N - 1, 0, -1):
		suffs.append(suffs[-1] + A[i])
	suffs = suffs[1:]
	suffs.sort(reverse=True)
	ans = sum(A)
	for i in range(K - 1):
		ans += suffs[i]
	return ans
print(solve())


(n, k) = [int(i) for i in input().split()]
data = [int(i) for i in input().split()]
span = data[-1] - data[0]
delta = [data[i + 1] - data[i] for i in range(n - 1)]
delta.sort(reverse=True)
print(span - sum(delta[:k - 1]))


import sys
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def read():
	tc = 0
	if tc:
		input = sys.stdin.readline
	else:
		sys.stdin = open('input1.txt', 'r')
		sys.stdout = open('output1.txt', 'w')

def solve():
	(n, k) = mi()
	a = li()
	b = []
	for i in range(n - 1):
		b.append(a[i + 1] - a[i])
	ans = a[n - 1] - a[0]
	b.sort(reverse=True)
	for i in range(k - 1):
		ans -= b[i]
	print(ans)
solve()


(n, k) = map(int, input().split())
s = [int(x) for x in input().split()]
arr = []
for i in range(1, len(s)):
	arr.append((s[i] - s[i - 1], i, i - 1))
arr = sorted(arr)
arr = arr[::-1]
ans = s[-1] - s[0]
for i in range(k - 1):
	ans += s[arr[i][2]]
	ans -= s[arr[i][1]]
print(ans)


R = lambda : map(int, input().split())
(n, k) = R()
L = list(R())
s = []
for i in range(1, n):
	s.append(L[i] - L[i - 1])
k = n - k
s = sorted(s)
print(sum(s[:k]))


def gns():
	return list(map(int, input().split()))
(n, k) = gns()
ns = gns()
if k == 1:
	print(ns[-1] - ns[0])
	quit()
x = []
for i in range(1, n):
	x.append(ns[i] - ns[i - 1])
k1 = k - 1
x.sort()
c = sum(x[-k1:])
print(ns[-1] - ns[0] - c)


(n, r) = map(int, input().split())
l = list(map(int, input().split()))
g = []
for i in range(1, n):
	g.append(l[i] - l[i - 1])
g.sort()
print(sum(g[:n - r]))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		(n, k) = LI()
		a = LI()
		r = a[-1] - a[0]
		if k > 1:
			t = []
			for (b, c) in zip(a[1:], a):
				t.append(b - c)
			t.sort(reverse=True)
			r -= sum(t[:k - 1])
		rr.append(r)
	return JA(rr, '\n')
print(main())


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
if n == 1:
	print(0)
else:
	b = []
	for i in range(0, n - 1):
		b.append(a[i + 1] - a[i])
	b.sort()
	s = 0
	for j in range(0, n - k):
		s += b[j]
	print(s)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
diff = [arr[i + 1] - arr[i] for i in range(n - 1)]
diff.sort()
if k != 1:
	diff = diff[:-(k - 1)]
print(sum(diff))


ln = [int(i) for i in input().split(' ')]
n = ln[0]
k = ln[1]
ln = [int(i) for i in input().split(' ')]
sm = 0
st = []
for i in range(1, len(ln)):
	st.append(ln[i] - ln[i - 1])
	sm += ln[i] - ln[i - 1]
st = sorted(st)[::-1]
for i in range(0, k - 1):
	sm -= st[i]
print(sm)


(n, k) = map(int, input().split())
mass = [int(i) for i in input().split()]
mass = mass[::-1]
summ = 0
m = []
for i in range(n - 1):
	summ += mass[i]
	m.append(summ)
m = sorted(m, reverse=True)
print(sum(mass) + sum(m[:k - 1]))


from sys import stdin
input = stdin.readline
INP = lambda : map(int, input().split())
(n, k) = INP()
(*a,) = INP()
b = []
for i in range(1, n):
	b.append(a[i] - a[i - 1])
k = min(k, len(b))
print(sum(sorted(b)[:n - k]))


(n, k) = [int(i) for i in input().split()]
array = [int(i) for i in input().split()]
summ = 0
sums_array = []
for i in range(len(array) - 1, 0, -1):
	summ += array[i]
	sums_array.append(summ)
sorted_sums = sorted(sums_array, reverse=True)
a = sorted_sums[:k - 1]
full_sum = sum(array) + sum(sorted_sums[:k - 1])
print(full_sum)


def find(A, n):
	if n == len(A):
		return 0
	temp = [A[i] - A[i + 1] for i in range(0, len(A) - 1)]
	temp = sorted(temp)
	a = sum(temp[:n - 1])
	return -A[0] + a + A[-1]
(N, k) = list(map(int, input().strip().split(' ')))
A = list(map(int, input().strip().split(' ')))
print(find(A, k))


def main():
	buf = input()
	buflist = buf.split()
	n = int(buflist[0])
	k = int(buflist[1])
	buf = input()
	buflist = buf.split()
	a = list(map(int, buflist))
	a_sum = []
	for i in range(1, len(a) + 1):
		if not a_sum:
			a_sum.append(a[-i])
		else:
			a_sum.append(a[-i] + a_sum[-1])
	cost = a_sum.pop()
	a_sum.sort(reverse=True)
	for i in range(k - 1):
		cost += a_sum[i]
	print(cost)
main()


(n, k) = input().split()
(n, k) = (int(n), int(k))
numbers = list(map(int, input().split()))
lst1 = []
for i in range(1, len(numbers)):
	lst1.append(numbers[i] - numbers[i - 1])
lst1.sort()
for i in range(k - 1):
	lst1.pop()
print(sum(lst1))


(n, k) = map(int, input().split())
l = [*map(int, input().split())]
d = sorted((l[i - 1] - l[i] for i in range(1, n)))
print(l[-1] - l[0] + sum(d[:k - 1]))


(n, k) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
diff = []
for i in range(1, len(l)):
	diff.append(l[i] - l[i - 1])
diff.sort()
if n != k:
	print(sum(diff[:-k]) + diff[-k])
else:
	print(0)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
temp = []
fsum = 0
for i in range(n - 1):
	temp.append(arr[i] - arr[i + 1])
temp.sort()
fsum = arr[n - 1] - arr[0]
for i in range(k - 1):
	fsum = fsum + temp[i]
print(fsum)


from itertools import accumulate
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
acc = list(accumulate(a))[:-1]
acc.sort()
ans = k * sum(a) - sum(acc[:k - 1])
print(ans)


(n, k) = [int(x) for x in input().split()]
L = [int(x) for x in input().split()]
ans = L[-1] - L[0]
L2 = []
for i in range(1, n):
	L2.append(L[i - 1] - L[i])
L2.sort()
for i in range(k - 1):
	ans += L2[i]
print(ans)


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
new_arr = []
for i in range(n - 1):
	new_arr.append(arr[i + 1] - arr[i])
new_arr.sort()
print(sum(new_arr[:n - k]))


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = []
for i in range(len(a) - 1):
	b.append(a[i + 1] - a[i])
b = sorted(b)
totalSum = sum(b)
newSum = 0
for i in range(len(b) - 1, len(b) - k, -1):
	newSum += b[i]
print(totalSum - newSum)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [0] * (n - 1)
ans = 0
for i in range(n - 1):
	b[i] = a[i] - a[i + 1]
b = sorted(b)
for i in range(k - 1):
	ans += b[i]
ans += a[n - 1] - a[0]
print(ans)


(n, k) = input().split()
n = int(n)
k = int(k)
inp = input()
a = [int(ele) for ele in inp.split()]
ans = a[-1] - a[0]
b = []
for i in range(n - 1):
	b.append(a[i + 1] - a[i])
b.sort()
b.reverse()
for i in range(0, k - 1):
	ans -= b[i]
print(ans)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
q = []
for i in range(n - 1):
	q.append(s[i + 1] - s[i])
q.sort()
ans = 0
for i in range(len(q) - (k - 1)):
	ans += q[i]
print(ans)


R = lambda : map(int, input().rstrip().split())
(n, m) = R()
a = list(R())
li = [0]
for i in range(n - 1):
	li.append(a[i + 1] - a[i])
li.sort(reverse=True)
print(sum(li[m - 1:]))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if n == k:
	print(0)
elif k == 1:
	print(l[-1] - l[0])
else:
	mini = 10 ** 18
	ans = []
	for i in range(n - 1):
		ans.append(l[i + 1] - l[i])
	ans.sort()
	print(sum(ans[:-k + 1]))


from sys import stdin
from math import sqrt, gcd
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
(n, k) = R()
a = list(R())
v = sorted([a[i - 1] - a[i] for i in range(1, n)])
ans = a[n - 1] - a[0]
for i in range(k - 1):
	ans += v[i]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if n == k:
	p = 0
elif k == 1:
	p = a[n - 1] - a[0]
else:
	for i in range(n - 1):
		a[i] = a[i + 1] - a[i]
	del a[n - 1]
	a.sort()
	n -= k
	p = 0
	for i in range(n):
		p += a[i]
print(p)


import sys
import math as mt
import bisect
input = sys.stdin.readline
t = 1

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve():
	l1 = []
	ans = l[-1] - l[0]
	for i in range(1, n):
		l1.append(l[i - 1] - l[i])
	l1.sort()
	d1 = {}
	suma = sum(l1[:k - 1])
	return suma + ans
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	print(solve())


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
chai = []
for i in range(1, n):
	chai.append(arr[i] - arr[i - 1])
chai.sort()
ans = sum(chai)
j = n - 2
for i in range(k - 1):
	ans -= chai[j]
	j -= 1
print(ans)


(n, k) = map(int, input().split())
lists = list(map(int, input().split()))
a = lists[-1] - lists[0]
dis = [0 for i in range(n - 1)]
for i in range(n - 1):
	dis[i] = lists[i + 1] - lists[i]
dis = sorted(dis, reverse=True)
b = sum(dis[:k - 1])
print(a - b)


(n, k) = map(int, input().split())
arr = [int(x) for x in input().split()]
diff = [arr[i] - arr[i - 1] for i in range(1, n)]
diff.sort(reverse=True)
cost = sum(diff)
for i in range(k - 1):
	cost -= diff[i]
print(cost)


(n, k) = map(int, input().split())
numbers = list(map(int, input().split()))
difference = [0] * (n - 1)
for i in range(n - 1):
	difference[i] = numbers[i + 1] - numbers[i]
difference.sort()
print(sum(difference[:n - k]))


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
s = []
for i in range(len(a) - 1):
	s.append(a[i + 1] - a[i])
s.sort()
print(sum(s[0:n - k]))


from sys import stdin, stdout
import collections
(N, K) = [int(x) for x in stdin.readline().split()]
arr = [int(x) for x in stdin.readline().split()]
d = []
for i in range(1, N):
	d.append(arr[i] - arr[i - 1])
d.sort(reverse=True)
res = arr[-1] - arr[0] - sum(d[:K - 1])
print(res)