#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> reg(n, 0);
  for (int i = 0; i < n; ++i) cin >> reg[i];
  sort(reg.begin(), reg.end());
  int g = 0;
  for (int i = 0; i < m; ++i) {
    if (reg[i] > 0) break;
    g -= reg[i];
  }
  cout << g << "\n";
  return 0;
}
