#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", 3, "inline")
using namespace std;
int mon[20] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
long long gcd(long long x, long long y) {
  return ((y == 0) ? x : gcd(y, x % y));
}
int a[2000];
int n, m;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  long long sum;
  for (int i = 0; i < m; i++) sum += a[i];
  cout << sum;
  return 0;
}
