#include <iostream>

using namespace std;

int main()
{
    int n, k, i;
    int p[i];
    cin >> n >> k;
    for ( i = 1; i <= k; i ++ )
       cin >> p[i];
    for ( int j = 1; j <= k - 1; j++ )
    {
        if ( p[1] >= p[i] )
            p[1] -= p[i];
        else
            p[1] = p[i] - p[1];
        i --;
    }
    cout << p[1] << endl;
    return 0;
}