#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
void Asc(void *base,const int count,const int size,const int index)
{
  typedef int rsort_t;
  rsort_t (*a)[size]=(rsort_t(*)[size])base;
  rsort_t (*b)[size]=(rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
  int c[0x100];
  memset(c,0,sizeof(c));rep(i,count){c[(a[i][index]>>(0<<3))&0xFF]++;}rep(i,0x99)c[i+1]+=c[i];rep(i,count){int to=--c[(a[count-i-1][index]>>(0<<3))&0xFF];rep(j,size){b[to][j]=a[count-i-1][j];}}{rsort_t(*t)[size]=a;a=b;b=t;}
  memset(c,0,sizeof(c));rep(i,count){c[(a[i][index]>>(1<<3))&0xFF]++;}rep(i,0x99)c[i+1]+=c[i];rep(i,count){int to=--c[(a[count-i-1][index]>>(1<<3))&0xFF];rep(j,size){b[to][j]=a[count-i-1][j];}}{rsort_t(*t)[size]=a;a=b;b=t;}
  memset(c,0,sizeof(c));rep(i,count){c[(a[i][index]>>(2<<3))&0xFF]++;}rep(i,0x99)c[i+1]+=c[i];rep(i,count){int to=--c[(a[count-i-1][index]>>(2<<3))&0xFF];rep(j,size){b[to][j]=a[count-i-1][j];}}{rsort_t(*t)[size]=a;a=b;b=t;}
  memset(c,0,sizeof(c));rep(i,count){c[(a[i][index]>>(3<<3))&0xFF]++;}rep(i,0x99)c[i+1]+=c[i];rep(i,count){int to=--c[(a[count-i-1][index]>>(3<<3))&0xFF];rep(j,size){b[to][j]=a[count-i-1][j];}}{rsort_t(*t)[size]=a;a=b;b=t;}
  free(b);
}
int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int main(void)
{
  int N=IN(),K=IN(),P[1000]={0},i=0,sum=0;
  while(i<N){P[i++]=IN();}
  Asc(P,N,1,0);
  i=0;
  while(i<K){sum+=P[i++];}
  return printf("%d\n",sum),0;
}