#include <stdio.h>
#include <iostream>

using namespace std;

int N,K;
int raznisa;
int a[10000];

int maximum(){
int i=0,maxx, sum=0, nomer;
while(i<raznisa){
maxx=-1;
//cout<<"Uh ti..."<<endl;
     for(int j=0;j<N;j++){
             if(maxx>=a[j]){
		   //maxx=a[j];
		}else{	
		   maxx=a[j];
		   //cout<<"Eto max:  "<<maxx<<endl;
		   nomer=j;
		   //cout<<"Eto nomer : "<<nomer<<endl;		   
		}
	}
sum=sum+maxx;
a[nomer]=-1000;
i++;
}
return sum;
}

int main(){

freopen("input.txt", "r", stdin);
freopen("output.txt","w", stdout);

cin>>N;
cin>>K;

for(int i=0;i<N;i++){
   cin>>a[i];
}
raznisa=N-K;
//cout<<raznisa<<endl;
    if(raznisa!=0) cout<<maximum();
    else cout<<"0";

	return 0;
}