#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{	int i,n,k,r,sum=0,a[100],t;
	char fname[]="C://A.in.txt\0";
FILE *fp;
fp=fopen(fname,"w");
scanf("%i %i",&n,&k);fprintf(fp,"%i %i",n,k);

for(i=0;i<n;i++)
	{
fp=fopen(fname,"a");
	scanf("%i",&a[i]);
fprintf(fp,"%i",a[i]);
}
fp=fopen(fname,"r");
fp=fopen("fp","rt");

r=a[0];
	for(i=0;i<n;i++)
	{r=a[i];
	for(t=i+1;i<n+1;k++)
		if(a[t]<r)
			r=a[i];
			
	
	a[n]=a[i];a[i]=r;}
for(i=n-k;i<n;i++)
sum+=a[i];
fp=fopen("C://A.out.txt\0", "w");
fprintf(fp,"%i",sum);
getch();
}