#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int i, j, s = 0, t;
  int arr[n];
  for (i = 0; i < n; i++) cin >> arr[i];
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (arr[i] > arr[j]) {
        t = arr[i];
        arr[i] = arr[j];
        arr[j] = t;
      }
    }
  }
  for (i = 0; i < m; i++) {
    if (arr[i] < 0)
      s = s - arr[i];
    else
      break;
  }
  cout << s;
}
