import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		PriorityQueue<Integer> pq = new PriorityQueue<>();

		int n,k = 0;
		n = scanner.nextInt();
		k = scanner.nextInt(); // 買う果物

		while (n-- > 0){
			pq.add(scanner.nextInt());
		}

		int sum = 0;
		while (k-- > 0){
			sum += pq.poll();
		}
		System.out.println(sum);

	}

} import java.util.PriorityQueue; PriorityQueue java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		PriorityQueue<Integer> pq = new PriorityQueue<>();

		int n,k = 0;
		n = scanner.nextInt();
		k = scanner.nextInt(); // 買う果物

		while (n-- > 0){
			pq.add(scanner.nextInt());
		}

		int sum = 0;
		while (k-- > 0){
			sum += pq.poll();
		}
		System.out.println(sum);

	}

} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		PriorityQueue<Integer> pq = new PriorityQueue<>();

		int n,k = 0;
		n = scanner.nextInt();
		k = scanner.nextInt(); // 買う果物

		while (n-- > 0){
			pq.add(scanner.nextInt());
		}

		int sum = 0;
		while (k-- > 0){
			sum += pq.poll();
		}
		System.out.println(sum);

	} main {
		Scanner scanner = new Scanner(System.in);
		PriorityQueue<Integer> pq = new PriorityQueue<>();

		int n,k = 0;
		n = scanner.nextInt();
		k = scanner.nextInt(); // 買う果物

		while (n-- > 0){
			pq.add(scanner.nextInt());
		}

		int sum = 0;
		while (k-- > 0){
			sum += pq.poll();
		}
		System.out.println(sum);

	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) PriorityQueue<Integer> pq = new PriorityQueue<>(); pq new PriorityQueue<>() int n n k = 0; k 0 n = scanner.nextInt() n scanner.nextInt() scanner.nextInt scanner k = scanner.nextInt() k scanner.nextInt() scanner.nextInt scanner while (n-- > 0){
			pq.add(scanner.nextInt());
		} n-- > 0 n-- n 0 {
			pq.add(scanner.nextInt());
		} pq.add(scanner.nextInt()) pq.add pq scanner.nextInt() scanner.nextInt scanner int sum = 0; sum 0 while (k-- > 0){
			sum += pq.poll();
		} k-- > 0 k-- k 0 {
			sum += pq.poll();
		} sum += pq.poll() sum pq.poll() pq.poll pq System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		PriorityQueue<Integer> pq = new PriorityQueue<>();

		int n,k = 0;
		n = scanner.nextInt();
		k = scanner.nextInt(); // 買う果物

		while (n-- > 0){
			pq.add(scanner.nextInt());
		}

		int sum = 0;
		while (k-- > 0){
			sum += pq.poll();
		}
		System.out.println(sum);

	}

} public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		PriorityQueue<Integer> pq = new PriorityQueue<>();

		int n,k = 0;
		n = scanner.nextInt();
		k = scanner.nextInt(); // 買う果物

		while (n-- > 0){
			pq.add(scanner.nextInt());
		}

		int sum = 0;
		while (k-- > 0){
			sum += pq.poll();
		}
		System.out.println(sum);

	}

} Main
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		PriorityQueue<Integer> pq = new PriorityQueue<>();

		int n,k = 0;
		n = scanner.nextInt();
		k = scanner.nextInt(); // 買う果物

		while (n-- > 0){
			pq.add(scanner.nextInt());
		}

		int sum = 0;
		while (k-- > 0){
			sum += pq.poll();
		}
		System.out.println(sum);

	}

}
