#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926536;
const long long INF = 1e18;
const int32_t M = 1e6 + 7;
const int32_t MM = 998244353;
long long n, m, j = 0;
long long s = 0;
long long a[M];
void solve() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (long long i = 0; i < m; i++)
    if (a[i] < 0) s += -a[i];
  cout << s;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) solve();
  return 0;
}
