#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int niz[1000000];

int main()
{
	int n, k;

	cin >> n >> k;

	for (int i = 0; i < n; i++)
	{
		cin >> niz[i];
	}

	sort(niz,niz+n);

	int suma = 0;

	for (int i = 0; i <= k/2; i++)
	{
		suma += niz[i];
	}

	for (int i = n-1; i >= n - k / 2; i--)
	{
		suma -= niz[i];
	}

	cout << suma;
}