#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(begin(a), end(a));
  long long ret = 0;
  for (int i = 0; i < m; i++) ret += a[i];
  printf("%lld\n", ret);
  return 0;
}
