#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define int long long
#define ld long double

using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    int ans = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = k - 1; i < n; i++) {
        vector<int> temp;
        for (int j = 0; j < i; j++) {
            temp.push_back(a[j]);
        }
        int pls = 0;
        if (!temp.empty()) {
            sort(temp.begin(), temp.end());
            reverse(temp.begin(), temp.end());
            for (int j = 0; j < k - 1; j++) {
                pls += temp[j];
            }
        }
        ans = max(ans, a[i] + i - (n - k) + pls + k);
    }
    cout << ans << '\n';
}
signed main() {
    solve();
}
