#include <bits/stdc++.h>
#define en '\n'
#define ll long long
#define sp " "

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    deque<int> a;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        a.push_back(x);
    }
    while (a.size() > 1)
    {
        a.back() -= a.front();
        a.pop_front();
    }
    cout << abs(a.back());
}