#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n, k;
	bool prvi = false;

	cin >> n >> k;

	vector<int> a(n);
	
	int m = n;

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

	if (k % 2 == 1)
	{
		k++;
	}

	for (int i = 1; i < k; i++)
	{
		if (a.front() > a.back())
		{
			int x = a[0] - a[m - 1];
			a.pop_back();
			a.erase(a.begin());
			a.insert(a.begin(), x);
			prvi = true;
			m--;
		}
		else
		{
			int x = a[m - 1] - a[0];
			a.pop_back();
			a.erase(a.begin());
			a.insert(a.end(), x);
			prvi = false;
			m--;
		}
	}

	if (prvi)
	{
		cout << a.front() << endl;
	}
	else
	{
		cout << a.back() << endl;
	}

	return 0;
}