#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = (int)2 * 1e5 + 10;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> arr(n);
  for (long long i = 0; i < n; i += 1) {
    cin >> arr[i];
  }
  sort((arr).begin(), (arr).end());
  long long sum = 0;
  for (long long i = 0; i < m; i++) {
    if (arr[i] < 0) {
      sum += arr[i];
    }
  }
  cout << abs(sum) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  solve();
  return 0;
}
