#include <bits/stdc++.h>
using namespace std;
int main() {
  int A[1002];
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> A[i];
  sort(A, A + n + 1);
  for (int num = 0, i = 1, last = 0; num < k; num++) {
    while (A[i] == last and i < n) i++;
    A[0] += A[i];
    last = A[i];
  }
  cout << A[0];
}
