#include <bits/stdc++.h>
using namespace std;
void sortIN(int p[], int a, int& index, int plus);
int main() {
  int n, k;
  int index = 0;
  int sum = 0;
  int* p;
  cin >> n >> k;
  p = new int[n];
  for (int i = 1; i < n; i++) {
    p[n] = 0;
  }
  cin >> p[0];
  for (int i = 0; i < (n - 1); i++) {
    int a;
    cin >> a;
    sortIN(p, a, index, 0);
  }
  for (int i = 0; i < k; i++) {
    sum += p[i];
  }
  cout << sum << endl;
  return 0;
}
void sortIN(int p[], int a, int& index, int plus) {
  if (p[index] <= a) {
    index++;
    if (index >= sizeof(p)) {
      return;
    }
    p[index] = a;
    index += plus;
  } else {
    p[index + 1] = p[index];
    index--;
    if (index < 0) {
      return;
    }
    plus++;
    sortIN(p, a, index, plus);
  }
}
