#include<bits/stdc++.h>
using namespace std;



int main(){
    int n, k, i, nap,sip;

    cin>>n>>k;
    vector<int> a;

    for(i = 0;i<n;i++){
        cin>>a[i];
    }

    sort(a.begin(), a.end());



    nap = a[0];
    sip = 0;
    while(sip <= k){
       nap = nap - a[n-sip];
       sip++;
    }
    cout<<nap;


    return 0;
}