#include <bits/stdc++.h>
using namespace std;
long long a[2000];
int main() {
  long long n, k;
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  a[1] = 0;
  for (long long i = 1; i <= k; i++) a[i] += a[i - 1];
  cout << a[k];
  cout << "\n";
  return 0;
}
