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

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))


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]))


(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)


(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) = 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()))
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) = 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]))


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]))


(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:]))


(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)


(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]))


(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)


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]))


(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) = 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:]))


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
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 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()


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())
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())
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))


(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]))


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)


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()


(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)


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()


(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())
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 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())
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)


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)


(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)


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]))


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) = 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)


(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)


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())
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]))


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())
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)


(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)


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) = 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)


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, 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]))


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]))


(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()


(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)


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]))


(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)


(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) = 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]))


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)


(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]))


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 = 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]))


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)


(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)


(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())
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)


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 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())
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)


(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)


(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)]))


(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)


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]))


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))


(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)


(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)


(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)