#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long N, M;
  cin >> N >> M;
  long long A[N];
  for (long long i = 0; i < N; i++) cin >> A[i];
  sort(A, A + N);
  long long sum = 0;
  for (long long i = 0; i < M; i++) sum += A[i];
  cout << sum << '\n';
  return 0;
}
