#include <bits/stdc++.h>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//int new_tnode(ll x, int tl, int tr, int l = 0, int r = 0);

template<class T>
struct TNode {
    T x;
    int tl, tr;
    int l = 0;
    int r = 0;
    T def;
    function<T(T, T)> sum;

    TNode(T x, T def, function<T(T, T)> sum, int tl, int tr, int l = 0, int r = 0) :
            x(x), def(def), sum(sum), tl(tl), tr(tr), l(l), r(r) {

    }

    // TNode() = default;
    TNode get_l() const {
        return l ? l : TNode<T>(def, tl, (tl + tr) / 2);
    }

    TNode get_r() const {
        return r ? r : TNode<T>(def, (tl + tr) / 2, tr);
    }

    T get(int ll, int rr) {
        if (tr <= ll || rr <= tl) return def;
        if (ll <= tl && tr <= rr) return x;
        return sum(get_l().get(ll, rr), get_r().get(ll, rr));
    }

    void insert(int i, T y) {
        if (tl == i && i + 1 == tr) {
            x = y;
        }
        int tm = (tl + tr) / 2;
        if (i < tm) {
            get_l().insert(i, y);
        } else {
            get_r().insert(i, y);
        }
        x = sum(get_l().x, get_r().x);
    }

};

//vector<TNode> tn(1);

//int new_tnode(ll x, int tl, int tr, int l, int r) {
//    tn.emplace_back(x, tl, tr, l, r);
//    return (int) tn.size() - 1;
//}

//template<class T>
//struct Tree {
//    TNode<T> root;
//    int n, N;
//    T def;
//    function<T(T, T)> sum;
//    Tree(int n, T def, function<T(T, T)> sum): n(n), def(def), sum(sum) {
//        int st = 0;
//        while ((1 << st) < n) ++st;
//        N = (1 << st);
//        root = TNode<T>(def, sum, 0, N);
//    }
//};
#define int ll

int n, k;
vector<ll> v;

//ll calc(int i, vector<pair<ll, ll>> &vv) {
//    if (i == n) {
//        ll res = 0;
//        for (int j = 0; j < k; ++j) {
//            if (vv[j].first == 0) return 0;
//            res += vv[j].second;
//        }
//        return res;
//    }
//    ll res = 0;
//    for (int j = 0; j < k; ++j) {
//        vv[j].first++;
//        ll old = vv[j].second;
//        vv[j].second = max(vv[j].second, v[i] + vv[j].first);
//        res = max(res, calc(i + 1, vv));
//        vv[j].first--;
//        vv[j].second = old;
//    }
//    return res;
//}
void solve() {

    cin >> n >> k;
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    vector<array<array<array<ll, 2>, 2>, 2>> dp(n + 1);
    for (int i = 0; i < n; ++i) {
        ll nw1 = max(dp[i][0][0][0] + 1 + v[i], dp[i][0][0][1]) + dp[i][0][1][1];
        ll nw2 = max(dp[i][1][0][0] + 1 + v[i], dp[i][1][0][1]) + dp[i][1][1][1];
        if (nw1 > nw2) {
            dp[i + 1][0][0][0] = dp[i][0][0][0] + 1;
            dp[i + 1][0][0][1] = max(dp[i][0][0][0] + 1 + v[i], dp[i][0][0][1]);
            dp[i + 1][0][1] = dp[i][0][1];
        } else {
            dp[i + 1][0][0][0] = dp[i][1][0][0] + 1;
            dp[i + 1][0][0][1] = max(dp[i][1][0][0] + 1 + v[i], dp[i][1][0][1]);
            dp[i + 1][0][1] = dp[i][1][1];
        }

        nw1 = max(dp[i][0][1][0] + 1 + v[i], dp[i][0][1][1]) + dp[i][0][0][1];
        nw2 = max(dp[i][1][1][0] + 1 + v[i], dp[i][1][1][1]) + dp[i][1][0][1];
        if (nw1 > nw2) {
            dp[i + 1][1][1][0] = dp[i][0][1][0] + 1;
            dp[i + 1][1][1][1] = max(dp[i][0][1][0] + 1 + v[i], dp[i][0][1][1]);
            dp[i + 1][1][0] = dp[i][0][0];
        } else {
            dp[i + 1][1][1][0] = dp[i][1][1][0] + 1;
            dp[i + 1][1][1][1] = max(dp[i][1][1][0] + 1 + v[i], dp[i][1][1][1]);
            dp[i + 1][1][0] = dp[i][1][0];
        }
    }
    ll res1 = dp[n][0][0][1] + dp[n][0][1][1];
    ll res2 = dp[n][1][0][1] + dp[n][1][1][1];
    cout << max(res1, res2);
}

signed main() {
    int t = 1;
//    cin >> t;
    for (int test = 0; test < t; ++test) {
        solve();
        cout << '\n';
    }
    cerr << clock() / 1000.0;
    return 0;
}
