#include "bits/stdc++.h"
#pragma GCC optimize("unroll-loops", "Ofast")
using namespace std;
#define ll long long
const int inf = 2e9;
const ll INF = 2e18;

//#define int ll
#include "ext/pb_ds/assoc_container.hpp"
using namespace __gnu_pbds;
typedef tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

random_device dev;
mt19937 rnd(dev());

template<typename T1, typename T2>
istream& operator >> (istream &in, pair<T1, T2> &a) {
    in >> a.first >> a.second;
    return in;
}

template<typename T1, typename T2>
ostream& operator << (ostream &out, pair<T1, T2> &a) {
    out << a.first << " " << a.second;
    return out;
}

template<typename T>
istream& operator >> (istream &in, vector<T> &a) {
    for (int i = 0; i < a.size(); i++)
        in >> a[i];
    return in;
}

template<typename T>
ostream& operator << (ostream &out, vector<T> &a) {
    for (auto &i: a)
        cout << i << " ";
    return out;
}

ll msMx(multiset<ll> &ms) {
    auto it = ms.end();
    it--;
    return *it;
}

vector<vector<int>> g;
vector<int> s;
int n, q;
vector<int> solve(int stop) {
    vector<int> res(n);
    set<pair<int, int>> st;
    st.insert({-s[0], 0});
    int cur = 0;
    while (!st.empty()) {
        auto [c, j] = *st.begin();
        st.erase(st.begin());
        res[j] = cur;
        cur++;
        for (int u: g[j]) {
            if (u == stop)
                st.insert({0, u});
            else
                st.insert({-s[u], u});
        }
    }
    return res;
}

vector<int> pos;
vector<vector<int>> cnt;
vector<int> tin, tout;
vector<int> req;
vector<int> resAns;
int timer = 0;
void dfsT(int v) {
    tin[v] = timer;
    timer++;
    for (int u: g[v]) {
        dfsT(u);
    }
    tout[v] = timer;
    timer++;
}

bool check(int v, int u) {
    return ((tin[v] <= tin[u]) && (tout[v] >= tout[u]));
}

void dfs(int v) {
    for (int i = 0; i < q; i++) {
        if (pos[req[i]] > pos[v])
            cnt[v][i] = 1;
    }

    for (int u: g[v]) {
        dfs(u);
        for (int i = 0; i < q; i++) {
            cnt[v][i] += cnt[u][i];
        }
    }
    for (int i = 0; i < q; i++) {
        if (check(v, req[i]))
            cnt[v][i] = 0;
        else
            resAns[i] = max(resAns[i], cnt[v][i]);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<ll> a(m);
    cin >> a;
    int cntOtr = (m - n + 1) / 2;
    if (n >= m)
        cntOtr = 0;
    ll sum = 0;

    for (ll x: a)
        sum += x;
    ll otr = 0;
    for (int i = 0; i < cntOtr; i++)
        otr += a[i];
    cout << sum - otr * 2 << "\n";
}
