#include "bits/extc++.h"

using namespace std;
using namespace __gnu_pbds;

using ordered_set = tree<int, null_type, less < int>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
istream &operator>>(istream &is, vector <T> &vec) {
      for (auto &elem: vec) is >> elem;
      return is;
}

template<class T>
ostream &operator<<(ostream &os, const vector <T> &vec) {
      for (auto &elem: vec) os << elem << ' ';
      os << '\n';
      return os;
}

//#pragma optimize("Ofast")
//#pragma optimize("unroll-loops")
//#pragma optimize("avx, avx2")

const int NOTH = 0;

struct Node {
      int val, tag;

      Node(int val = 0, int tag = NOTH) : val(val), tag(tag) {}

      void apply(int v, int l, int r) {
            val += (r - l) * v;
            tag += v;
      }

      friend Node operator+(const Node &x, const Node &y) {
            return {x.val + y.val, NOTH};
      }
};

struct Lazy_Segtree {
      int size;
      vector <Node> tree;

      Lazy_Segtree(int n) {
            size = 1;
            while (size < n) size <<= 1;
            tree.resize(size << 1, Node());
      }

      Lazy_Segtree(const vector<int> &a) : Lazy_Segtree(a.size()) {
            for (int i = 0; i < a.size(); ++i) tree[i + size] = a[i];
            for (int i = size - 1; i > 0; --i) tree[i] = tree[i << 1] + tree[i << 1 | 1];
      }

      void push(int x, int lx, int rx) {
            if (rx - lx == 1 or tree[x].tag == NOTH) return;

            int mid = (lx + rx) >> 1;
            tree[x << 1].apply(tree[x].tag, lx, mid);
            tree[x << 1 | 1].apply(tree[x].tag, mid, rx);

            tree[x].tag = NOTH;
      }

      void set(int l, int r, int v, int x, int lx, int rx) {
            push(x, lx, rx);
            if (rx <= l or r <= lx) return;
            if (l <= lx and rx <= r) tree[x].apply(v, lx, rx);
            else {
                  int mid = (lx + rx) >> 1;

                  set(l, r, v, x << 1, lx, mid);
                  set(l, r, v, x << 1 | 1, mid, rx);

                  tree[x] = tree[x << 1] + tree[x << 1 | 1];
            }
      }

      Node get(int l, int r, int x, int lx, int rx) {
            push(x, lx, rx);
            if (rx <= l or r <= lx) return Node();
            if (l <= lx and rx <= r) return tree[x];
            else {
                  int mid = (lx + rx) >> 1;

                  Node s1 = get(l, r, x << 1, lx, mid);
                  Node s2 = get(l, r, x << 1 | 1, mid, rx);

                  return s1 + s2;
            }
      }

      void set(int l, int r, int v) {
            set(l, r, v, 1, 0, size);
      }

      Node get(int l, int r) {
            return get(l, r, 1, 0, size);
      }
};

int dgcd(int a, int b, int &x, int &y) {
      if (a == 0) {
            x = 0, y = 1;
            return b;
      }

      int x1, y1;
      int d = dgcd(b % a, a, x1, y1);
      x = y1 - (b / a) * x1;
      y = x1;

      return d;
}


signed main() {
#ifdef LOCAL
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
#else
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
#endif
      int n, k;
      cin >> n >> k;
      vector<int> a(n);
      cin >> a;

      vector <pair<int, int>> b(n);
      for (int i = 0; i < n; ++i) b[i] = {a[i], i};

      std::sort(b.rbegin(), b.rend());
      int res = 0;
      for (int u = 0; u < k; ++u) {
            int now = 0;
            vector<int> used(n);
            for (int i = 0; i < k; ++i) {
                  if (i == u) continue;
                  now += b[i].first + 1, used[b[i].second] = true;
            }

            int mx = 0, cnt = 0;
            for (int i = 0; i < n; ++i) {
                  if (used[i]) continue;
                  mx = max(mx, a[i] + (++cnt));
            }
            res = max(res, mx + now);
      }
      cout << res << endl;

}