#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, N;
  int* p;
  cin >> N;
  cin >> K;
  p = new int[N];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  int S;
  for (int i = 0; i < N - 1; i++) {
    for (int m = i; m < N - 1; m++) {
      if (p[m] >= p[m + 1]) {
        S = p[m];
        p[m] = p[m + 1];
        p[m + 1] = S;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < K; i++) {
    ans = ans + p[i];
  }
  cout << ans;
}
