#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

typedef long long ll;

using namespace std;

void fio() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

class SegmentTree {

private:

    int size;

    std::vector<int> tree;

    std::vector<int> sz;

    int getMaxTree(int v, int left, int right, int qLeft, int qRight) {
        if (qRight <= left || right <= qLeft) {
            return 0LL;
        } else if (qLeft <= left && right <= qRight) {
            return tree[v];
        }
        int mid = (left + right) / 2;
        return max(getMaxTree(2 * v + 1, left, mid, qLeft, qRight),
                mid - qLeft + 1 + getMaxTree(2 * v + 2, mid, right, qLeft, qRight));
    }

    void updateTree(int v, int left, int right, int qPos, int qVal) {
        if (right - left == 1) {
            tree[v] = qVal;
            return;
        }
        int mid = (left + right) / 2;
        if (qPos < mid) {
            updateTree(2 * v + 1, left, mid, qPos, qVal);
        } else {
            updateTree(2 * v + 2, mid, right, qPos, qVal);
        }
    }

public:

    SegmentTree(const std::vector<int> &a) {
        size = 1;
        while (size < (int) a.size()) {
            size <<= 1;
        }
        tree.resize(2 * size);
        sz.resize(2 * size, 0);
        for (int i = 0; i < (int) a.size(); i++) {
            tree[size - 1 + i] = a[i];
            sz[size - 1 + i] = 1;
        }
        for (int v = size - 2; v >= 0; v--) {
            tree[v] = max(tree[2 * v + 1], sz[2 * v + 1] + tree[2 * v + 2]);
            sz[v] = sz[2 * v + 1] + sz[2 * v + 2];
        }
    }

    int getMax(int qLeft, int qRight) {
        return getMaxTree(0, 0, size, qLeft, qRight);
    }
};

void solveA() {
    int maxX, n, maxY, m, k, nQ;
    cin >> maxX >> n >> maxY >> m >> k >> nQ;
    vector<pair<int, int>> a(n);
    vector<int> sumA(n + 1, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
        sumA[i + 1] = a[i].first + sumA[i];
    }
    vector<int> sumB(m + 1, 0);
    vector<pair<int, int>> b(m);
    for (int i = 0; i < m; i++) {
        cin >> b[i].first >> b[i].second;
        sumB[i + 1] = sumB[i] + b[i].first;
    }
    vector<vector<bool>> res(n + 1, vector<bool>(m + 1, false));
    for (int i = n - 1; i >= 0; i--) {
        for (int j = m - 1; j >= 0; j--) {
            res[i][j] = res[i + 1][j] || res[i][j + 1];
            if (a[i].second == b[j].second) {
                res[i][j] = res[i][j] || min(a[i].first, b[j].first) % 2 == 1;
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << i << ':';
        for (int j = 0; j < m; j++) {
            if (res[i][j]) {
                cout << ' ' << 1;
            } else {
                cout << ' ' << 0;
            }
        }
        cout << '\n';
    }
    int qI, qJ;
    int posI, posJ;
    for (int i = 0; i < nQ; i++) {
        cin >> qI >> qJ;
        posI = std::upper_bound(sumA.begin(), sumA.end(), qI) - sumA.begin() - 1;
        posJ = std::upper_bound(sumB.begin(), sumB.end(), qJ) - sumB.begin() - 1;
        if (res[posI + 1][posJ] || res[posI][posJ + 1] || min(a[posI].first - qI + sumA[posI], b[posJ].first - qJ + sumB[posJ]) % 2 == 1) {
            cout << "Yes" << '\n';
        } else {
            cout << "No" << '\n';
        }
    }
}

void solveB() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    int cnt1 = 0;
    int cnt0 = 0;
    for (int i = 0; i < m; i++) {
        cin >> a[i];
        if (a[i] > 0) {
            cnt1++;
        } else if (a[i] < 0) {
            cnt0++;
        } else {
            cnt1++;
            cnt0++;
        }
    }
    ll ans = 0;
    if (n == 1) {
        for (int i = 0; i < m; i++) {
            ans = a[i] - ans;
        }
    } else if (n == 2) {
        ans = max(a[1] - a[0], a[1] + a[0]);
        for (int i = 3; i < m; i += 2) {
            ans += max(a[i] - a[i - 1], a[i - 1] - a[i]);
        }
        if (m % 2 == 1) {
            ans += abs(a[m - 1]);
        }
    } else {
        for (int i = 0; i < m; i++) {
            if (i < n || (i - n) % 2 == 1) {
                ans += a[i];
            } else {
                ans -= a[i];
            }
        }
    }
    cout << ans;
    return;
    int minus = (m - n + 1) / 2;
    vector<int> tmp = a;
    sort(tmp.rbegin(), tmp.rend());
    std::multiset<ll> cur;
    for (int i = 0; i < n; i++) {
        cur.insert(0);
    }
    for (int i = 0; i < m; i++) {
        if (a[i] > 0) {
            if (*cur.begin() <= 0 || cnt1 == 1) {
                ll next = a[i] - *cur.begin();
                cur.erase(cur.begin());
                cur.insert(next);
            } else if (cnt1 > 1) {
                ll next = a[i] - *cur.rbegin();
                auto t = cur.end();
                t--;
                cur.erase(t);
                cur.insert(next);
            }
        } else if (a[i] < 0) {

        }
        if (a[i] >= 0) {
            cnt1--;
        }
        if (a[i] <= 0) {
            cnt0--;
        }
        for (ll next : cur) {
            cout << next << ' ';
        }
        cout << '\n';
    }
    for (ll next : cur) {
        ans += next;
    }
    cout << ans;
}

void solveC() {
    int nV, nQ;
    cin >> nV >> nQ;
    vector<vector<int>> edges(nV);
    int from;
    for (int to = 1; to < nV; to++) {
        cin >> from;
        edges[from - 1].push_back(to);
    }
    vector<int> a(nV);
    for (int i = 0; i < nV; i++) {
        cin >> a[i];
    }
    vector<int> minD(nV);

}

void solveD() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if (k == 2) {
        vector<int> prefMax(n);
        prefMax[0] = a[0] + 1;
        for (int i = 1; i < n; i++) {
            prefMax[i] = max(prefMax[i - 1], a[i] + i + 1);
        }
        SegmentTree tree(a);
        int res = 0;
        for (int i = 0; i < n; i++) {
            res = max(res, prefMax[i] + tree.getMax(i + 1, n));
        }
    }
}

int main() {
    fio();
    solveD();
    return 0;
    int t;
    cin >> t;
    while (t--) {
        solveB();
        cout << '\n';
    }
    return 0;
}
/*
1
1 3
-1 -2 -3
0
 */