#include <bits/stdc++.h>
using namespace std;
void solve(int m, int arr[]) {
  int loss = 0;
  for (int i = 0; i < m; i++) {
    if (arr[i] >= 0) {
      break;
    }
    loss += arr[i];
  }
  cout << abs(loss) << endl;
}
int main() {
  int n, m;
  cin >> n >> m;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  solve(m, arr);
}
