#include <bits/stdc++.h>
#include <vector>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    long n, k, p = 0, l;
    cin>>n>>k;
    int niz[n];
    for(int i = 0; i < n; i++)
        cin>>niz[i];
    short f;

    if(n%2 == 0)
    {
        f = 0;
    }
    else
    {
        f = 1;
    }
    n--;
    while(p < n)
    {
        if(niz[p] < 0)
            {
                if(niz[n] < 0)
                {
                    niz[p]-=niz[n];
                    l = p;
                    n--;
                }
                else
                {
                    niz[n]-=niz[p];
                    l = n;
                    p++;;
                }
            }
            else
            {
                if(niz[n] < 0)
                {
                    niz[n]-=niz[p];
                    l = n;
                    p++;
                }
                else
                {
                    niz[p]-=niz[n];
                    l = p;
                    n--;
                }
            }
    }
    cout<<niz[p];


}