#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];
  vector<int> q(k);
  for (int i = 0; i < (k); ++i) q[i] = p[i];
  for (int i = 0; i < (n); ++i)
    for (int j = 0; j < (k); ++j) {
      if (p[i] < q[j]) {
        q[j] = p[i];
        break;
      }
    }
  int ans = 0;
  for (int i = 0; i < (k); ++i) ans += q[i];
  cout << ans << endl;
  return 0;
}
