#include <iostream>
#include <vector>
#include <limits>

int main()
{
	int num_potions, num_allowed;
	int power;

	std::cin >> num_potions >> num_allowed;

	std::vector<int> potions;

	for(int i = 0; i < num_potions; i++)
	{
		int input;
		std::cin >> input;
		potions.emplace_back(input);
	}
	
	for(int i = 1; i < num_allowed; i++)
	{
		int try1 = potions.front() - potions.back();
		int try2 = potions.back() - potions.front();
		
		if(try1 > try2)
		{
			potions.front() = try1;
			power = try1;
			potions.pop_back();
		}
		else
		{
			potions.back() = try2;
			power = try2;
			potions.erase(potions.begin());
		}
	}
	
	std::cout << power;

	return 0;
}