import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") n,k = list(map(int, input().split())) a = list(map(int, input().split())) ans = 0 x = a[0] for i in range(n-k): ans += -1 * (a[n-1-i] - x) for i in range(k): ans += (a[i] - x) print(ans)