#include<stdio.h>

int main(){
  int N,K,tmp,sum;
  scanf("%d%d",&N,&K);
  
  int p[N];
  for(int i=0;i<=N;i++){
    scanf("%d",&p[i]);
  }
  
  for(int i=0; i<N; i++) {
    for(int j=i+1; j<N; j++) {
      
      if(p[i] > p[j]) {
        
        tmp = p[i];
        p[i] = p[j];
        p[j] = tmp;
        
      }
      
    } 
  }
  
  for(int i=0;i<=K;i++){
    sum = sum+p[i]
  }
  
  printf("%d",&sum);
  
  return 0;
}
