#include <bits/stdc++.h>
using namespace std;
void swap(int *x, int *y) {
  int z = *x;
  *x = *y;
  *y = z;
}
class HeapTree {
 public:
  void push(int x) {
    tree.push_back(x);
    int focus = tree.size() - 1;
    while (true) {
      if (focus != 0 && tree[focus] < tree[focus / 2]) {
        swap(&tree[focus], &tree[focus / 2]);
        focus /= 2;
      } else {
        break;
      }
    }
  }
  int pop() {
    int r = tree[0];
    int l = tree[tree.size() - 1];
    tree.pop_back();
    tree[0] = l;
    int focus = 0;
    int cand1 = focus * 2 + 1;
    int cand2 = focus * 2 + 2;
    while (1) {
      int c = 0;
      if (cand1 >= tree.size()) {
        break;
      }
      if (cand2 >= tree.size()) {
        c = cand1;
      } else if (tree[cand1] < tree[cand2]) {
        c = cand1;
      } else {
        c = cand2;
      }
      if (tree[focus] > tree[c]) {
        swap(&tree[focus], &tree[c]);
        focus = c;
        cand1 = focus * 2 + 1;
        cand2 = focus * 2 + 2;
      } else {
        break;
      }
    }
    return r;
  }
  vector<int> getTree() { return tree; }

 private:
  vector<int> tree;
};
int main() {
  int N;
  int K;
  HeapTree p;
  cin >> N;
  cin >> K;
  for (int i = 0; i < N; ++i) {
    int t;
    cin >> t;
    p.push(t);
  }
  int sum = 0;
  for (int i = 0; i < K; ++i) {
    sum += p.pop();
  }
  cout << sum << endl;
}
