#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

template<typename T>
istream& operator>>(istream& in, vector<T>& v) {
    for (T& x : v) in >> x;
    return in;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T>& v) {
    for (T& x : v) out << x << " ";
    return out;
}

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

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

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
using ld = long double;

mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int& x : v) cin >> x;

    ll ans = 0;
    for (int pr = k - 1; pr < n; pr++) {
        vector<pair<int, int>> t(pr);
        for (int i = 0; i < pr; i++) t[i] = {v[i], i};
        sort(rall(t));

        ll res = v[pr];
        for (int i = 0; i < k - 1; i++) {
            res += t[i].first;
        }
        ans = max(ans, res + pr + 1);
    }
    cout << ans;
}

signed main() {
#ifndef LOCAL
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
#endif

    int t = 1;
//    cin >> t;
    while (t--) solve();
}