#include <bits/stdc++.h>
using namespace std;
int main()
{
    //k==n
    int n, k;
    cin >> n >> k;
    int a;
    vector<int> input;
    while (cin >> a) {
        input.push_back(a);
    }
    int l = 0;
    int r = input.size() - 1;
    while (l!=r) {
        int raz1 = input[l] - input[r];
        int raz2 = input[r] - input[l];
        if (raz2 >= raz1) {
            input[r] = raz2;
            l++;
        }
        if (raz1 > raz2) {
            input[l] = raz1;
            r--;
        }
    }
    cout << input[l] << '\n';
}