i번째 원생과 i+1번째 원생의 키 차이를 저장한 배열을 내림차순으로 정렬해줍니다.
이 배열을 작은 순서대로 k만큼 남게 슬라이싱을 해준 후, sum을 이용해 전부 더해준 뒤 출력합니다.
n, k = map(int, input().split())
people = list(map(int, input().split()))
diff = sorted([people[i+1]-people[i] for i in range(0, n-1)], reverse=True)
answer = diff[k-1:]
print(sum(answer))