#include <bits/stdc++.h>
using namespace std;
long long x, y, sum = 0, a[1000004], dp[1000004];
int main() {
  cin >> x >> y;
  for (int i = 0; i < x; i++) cin >> a[i];
  sort(a, a + x);
  for (int i = x - 1; i >= 0; i--) {
    sum += a[i];
    if (a[i] != 0) y--;
    if (y == 0) break;
  }
  if (sum > 0)
    cout << sum;
  else
    cout << 0;
}
