#include<bits/stdc++.h>
#define mod 998544343
#define inf 9187201950435737471
using namespace std;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
return x*f;
}
void write(long long x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
return;
}
int n,k,x;
long long ans;
priority_queue<int,vector<int>,greater<int> > q;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
n=read(),k=read();
while(n--){
x=read();
q.push(x);
if(q.size()>k){
q.pop();
}
}
while(!q.empty()){
ans+=q.top();
q.pop();
}
write(ans);
return 0;
}