import java.util.*;
import java.io.*;
import java.lang.*;


class Main{
	public static void main(String args[]){
    	Scanner in = new Scanner(System.in);
      	int n = in.nextInt();
		int m = in.nextInt();
		int[] ar = new int[n];
		for(int i = 0 ; i < n ; i++){
			ar[i] = in.nextInt();
		}
		
		Arrays.sort(ar);

		int cost = 0;
		for(int i = 0 ; i < m ; i++){
			cost += ar[i];
		}
		
		System.out.println(cost);
    }
 
} import java.util.*; util.* java import java.io.*; io.* java import java.lang.*; lang.* java class Main{
	public static void main(String args[]){
    	Scanner in = new Scanner(System.in);
      	int n = in.nextInt();
		int m = in.nextInt();
		int[] ar = new int[n];
		for(int i = 0 ; i < n ; i++){
			ar[i] = in.nextInt();
		}
		
		Arrays.sort(ar);

		int cost = 0;
		for(int i = 0 ; i < m ; i++){
			cost += ar[i];
		}
		
		System.out.println(cost);
    }
 
} Main public static void main(String args[]){
    	Scanner in = new Scanner(System.in);
      	int n = in.nextInt();
		int m = in.nextInt();
		int[] ar = new int[n];
		for(int i = 0 ; i < n ; i++){
			ar[i] = in.nextInt();
		}
		
		Arrays.sort(ar);

		int cost = 0;
		for(int i = 0 ; i < m ; i++){
			cost += ar[i];
		}
		
		System.out.println(cost);
    } main {
    	Scanner in = new Scanner(System.in);
      	int n = in.nextInt();
		int m = in.nextInt();
		int[] ar = new int[n];
		for(int i = 0 ; i < n ; i++){
			ar[i] = in.nextInt();
		}
		
		Arrays.sort(ar);

		int cost = 0;
		for(int i = 0 ; i < m ; i++){
			cost += ar[i];
		}
		
		System.out.println(cost);
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int m = in.nextInt(); m in.nextInt() in.nextInt in int[] ar = new int[n]; ar new int[n] n for(int i = 0 ; i < n ; i++){
			ar[i] = in.nextInt();
		} int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
			ar[i] = in.nextInt();
		} {
			ar[i] = in.nextInt();
		} ar[i] = in.nextInt() ar[i] ar i in.nextInt() in.nextInt in Arrays.sort(ar) Arrays.sort Arrays ar int cost = 0; cost 0 for(int i = 0 ; i < m ; i++){
			cost += ar[i];
		} int i = 0 ; int i = 0 ; i 0 i < m i m i++ i++ i {
			cost += ar[i];
		} {
			cost += ar[i];
		} cost += ar[i] cost ar[i] ar i System.out.println(cost) System.out.println System.out System System.out cost String args[] args
import java.util.*;
import java.io.*;
import java.lang.*;


class Main{
	public static void main(String args[]){
    	Scanner in = new Scanner(System.in);
      	int n = in.nextInt();
		int m = in.nextInt();
		int[] ar = new int[n];
		for(int i = 0 ; i < n ; i++){
			ar[i] = in.nextInt();
		}
		
		Arrays.sort(ar);

		int cost = 0;
		for(int i = 0 ; i < m ; i++){
			cost += ar[i];
		}
		
		System.out.println(cost);
    }
 
}