#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, K;
  cin >> N >> K;
  int P[1000];
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  int v, j;
  for (int i = 0; i < N; i++) {
    v = P[i];
    j = i - 1;
    while (j >= 0 && P[j] > v) {
      P[j + 1] = P[j];
      j--;
    }
    P[j + 1] = v;
  }
  int total;
  for (int i = 0; i < K; i++) {
    total = total + P[i];
  }
  cout << total;
}
