#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,k,a;
    cin >> n >> k;
    deque<int> jacine;
    for(int i = 0; i < n; i++)
    {
        cin >> a;
        jacine.push_back(a);
    }
    while(jacine.size() > 2)
    {
        if(jacine[0] >= jacine[jacine.size()-1])
        {
            jacine[jacine.size()-1]-=jacine[0];
            jacine.pop_front();
        }else
        {
            jacine[0]-=jacine[jacine.size()-1];
            jacine.pop_back();
        }
    }
    if(jacine[0] <= jacine[jacine.size()-1])
    {
        jacine[jacine.size()-1]-=jacine[0];
        jacine.pop_front();
    }else
    {
        jacine[0]-=jacine[jacine.size()-1];
        jacine.pop_back();
    }
    cout << jacine[0];
}