#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define fi first
#define se second
vector<ll> tree;
void build(ll v, ll l, ll r, vector<ll> &a) {
    if (r - l == 1) {
        tree[v] = a[l];
        return;
    }
    ll m = (l + r) / 2;
    build(2 * v + 1, l, m, a);
    build(2 * v + 2, m, r, a);
}

void update(ll v, ll l, ll r, ll ql, ll qr, ll x) {
    if (l >= qr || r <= ql) {
        return;
    }
    if (l >= ql && r <= qr) {
        tree[v] = x;
        return;
    }
    ll m = (l + r) / 2;
    update(2 * v + 1, l, m , ql, qr, x);
    update(2 * v + 2, m, r, ql, qr, x);
    tree[v] = tree[2 * v + 1] + tree[2 * v + 2];
}



void solve() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m);
    for(int i = 0; i < m; ++i) {
        cin >> a[i];
    }
    const ll sum = 2 * 400 * 400 + 2;
    vector<vector<ll>> dp(sum, vector<ll> (2, -1));
    ll zer = 400 * 400;
    dp[zer][0] = a[0];
    dp[zer + a[0]][1] = 0;
    for(int i = 1; i < m; ++i) {
        vector<vector<ll>> ndp(sum, vector<ll> (2, -1));
        for(int j = 0; j < sum; ++j) {
            if (dp[j][0] != -1) {
                ndp[j][0] = max(ndp[j][0], -dp[j][0] + a[i]);
                ll real = j - zer;
                ll nw = j - 2 * real + a[i];
                if (nw >= 0 && nw < sum) {
                    ndp[nw][1] = max(ndp[nw][1], dp[j][0]);
                }
            }
            if (dp[j][1] != -1) {
                ndp[j][1] = max(ndp[j][1], -dp[j][1] + a[i]);
                ll real = j - zer;
                ll nw = j - 2 * real + a[i];
                if (nw >= 0 && nw < sum) {
                    ndp[nw][0] = max(ndp[nw][0], dp[j][1]);
                }
            }
        }
        dp = ndp;
    }
    ll mx = 0;
    for(int i = 0; i < sum; ++i) {
        for(int j = 0; j < 2; ++j) {
            if (dp[i][j] != -1) {
                //cout << i - zer << ' ' << dp[i][j] << ' ' << j << '\n';
                mx = max(mx, i - zer + dp[i][j]);
            }
        }
    }
    cout << mx;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll T = 1;
    //cin >> T;
    while(T--) {
        solve();
        cout << '\n';
    }
    return 0;
}
