#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i <= N; i++) {
    cin >> p[i];
  }
  int tmp;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (p[j] < p[i]) {
        tmp = p[i];
        p[i] = p[j];
        p[j] = tmp;
      }
    }
  }
  int sum = 0;
  for (int i = 0; i <= K; i++) {
    sum += p[i];
  }
  cout << sum << endl;
}
