#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < (n); ++i) cin >> p[i];
  int MAX = 0;
  for (int i = 0; i < (n); ++i) {
    if (i < k)
      MAX = max(MAX, p[i]);
    else {
      for (int j = 0; j < (k); ++j) {
        if (p[i] < MAX) {
          if (p[j] == MAX) {
            p[j] = p[i];
            MAX = p[i];
            break;
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < (k); ++i) ans += p[i];
  cout << ans << endl;
  return 0;
}
