#include <bits/stdc++.h>
using namespace std;
vector<int> p;
void QS(int a, int b) {
  if (b - a <= 1) {
    if (p.at(b) < p.at(a)) {
      swap(p.at(b), p.at(a));
    }
    return;
  }
  int c = (a + b) / 2;
  int P = p.at(c);
  int i = a, j = b;
  int X, Y;
  while (true) {
    while (i <= c) {
      if (p.at(i) >= P) {
        break;
      }
      i++;
    }
    while (j >= c) {
      if (p.at(j) <= P) {
        break;
      }
      j--;
    }
    if (i == c && j == c) {
      X = c - 1, Y = c + 1;
    } else if (i == c && j != c) {
      swap(p.at(i), p.at(j));
      X = c - 1, Y = c;
    } else if (i != c && j == c) {
      swap(p.at(i), p.at(j));
      X = c, Y = c + 1;
    } else {
      swap(p.at(i), p.at(j));
      continue;
    }
    break;
  }
  if (X - a <= 1) {
    if (p.at(X) < p.at(a)) {
      swap(p.at(X), p.at(a));
    }
  } else {
    QS(a, X);
  }
  if (b - Y <= 1) {
    if (p.at(b) < p.at(Y)) {
      swap(p.at(b), p.at(Y));
    }
  } else {
    QS(Y, b);
  }
  return;
}
int main() {
  int N, K, Z = 0;
  cin >> N >> K;
  p.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  QS(0, N - 1);
  for (int i = 0; i < K; i++) {
    Z += p.at(i);
  }
  cout << Z << endl;
}
