#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, K;
  int p[1000];
  int min[1000];
  int posi[1000];
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    min[i] = 1001;
    posi[i] = -1;
  }
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < N; j++) {
      if (min[i] > p[j]) {
        min[i] = p[j];
        posi[i] = j;
      }
      p[posi[i]] = 1001;
    }
  }
  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += min[i];
  }
  cout << ans << endl;
}
