#include <bits/stdc++.h>
using namespace std;
int prime(int a) {
  for (int i = 2; i <= a / 2; i++) {
    if (a % i == 0) return 0;
  }
  return 1;
}
string srt(string s) {
  int x = s.length();
  for (int i = 0; i < x; i++) {
    for (int j = 0; j < x; j++) {
      if (s[i] < s[j]) {
        char c = s[i];
        s[i] = s[j];
        s[j] = c;
      }
    }
  }
  return s;
}
int main() {
  int n, m;
  cin >> n;
  cin >> m;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int sum = 0;
  for (int i = 0; i < m; i++) {
    if (a[i] <= 0)
      sum = sum + abs(a[i]);
    else
      break;
  }
  cout << sum;
}
