#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i, n, k, seged, kisebb, nagyobb;
    scanf("%d %d", &n, &k);
    int tn[n], felso=n-1, also=0;
    for(i=0; i<n; i++)
        scanf("%d", &tn[i]);
    for(i=0; i<n-2; i++)
    {
        if(tn[also]>tn[felso])
        {
            tn[felso]=tn[felso]-tn[also];
            also++;
        }
        else
        {
            tn[also]=tn[also]-tn[felso];
            felso--;
        }
    }
    if(tn[also]>tn[felso])
    {
        tn[also]=tn[also]-tn[felso];
        printf("%d", tn[also]);
    }
    else
    {
        tn[felso]=tn[felso]-tn[also];
        printf("%d", tn[felso]);
    }
    return 0;
}