#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m;
  cin >> n >> m;
  long long int a[n], k = 0, sum = 0;
  for (int x = 0; x < n; x++) {
    cin >> a[x];
  }
  sort(a, a + n);
  for (int x = 0; x < m; x++) {
    if (a[x] < 0) {
      sum += a[x];
    }
  }
  cout << -sum << endl;
}
