#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int arr[n];
  priority_queue<int,vector<int>,greater<int>> pq;
  for(i=0;i<n;i++)
  {
    cin>>arr[i];
    pq.push(arr[i]);
  }
  int sum=0;
  while(k--)
    sum+=pq.pop();
  
  cout<<sum<<"\n";
  
  return 0;
  
  
}