#include <bits/stdc++.h>
using namespace std;
int dp[101][101];
int knapsack(vector<int> &cost, int n, int cap) {
  if (n == 0 || cap == 0) return 0;
  if (dp[n][cap] != -1) return dp[n][cap];
  int res = knapsack(cost, n - 1, cap - 1) - cost[n - 1];
  res = max(res, knapsack(cost, n - 1, cap));
  return dp[n][cap] = res;
}
void Rahul() {
  memset(dp, -1, sizeof(dp));
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int &i : a) cin >> i;
  cout << knapsack(a, a.size(), m);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  Rahul();
  return 0;
}
