#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int total = 0;
  int cost[101];
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> cost[i];
  sort(cost, cost + n);
  for (int i = 0; i < m; i++) total = max(total, total - cost[i]);
  cout << total;
}
