import java.util.Arrays;
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
       Scanner s = new Scanner(System.in);
       int size = s.nextInt();
       int k = s.nextInt();
       int elements[] = new int[size];
       for(int i=0;i<size;i++) {
           elements[i] = s.nextInt();
       }
       Arrays.sort(elements);
       long sum = 0;
       for(int i=0;i<k&&i<size;i++) {
           sum += elements[i];
       }
       System.out.println(sum);
   }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
   public static void main(String[] args) {
       Scanner s = new Scanner(System.in);
       int size = s.nextInt();
       int k = s.nextInt();
       int elements[] = new int[size];
       for(int i=0;i<size;i++) {
           elements[i] = s.nextInt();
       }
       Arrays.sort(elements);
       long sum = 0;
       for(int i=0;i<k&&i<size;i++) {
           sum += elements[i];
       }
       System.out.println(sum);
   }
} Main public static void main(String[] args) {
       Scanner s = new Scanner(System.in);
       int size = s.nextInt();
       int k = s.nextInt();
       int elements[] = new int[size];
       for(int i=0;i<size;i++) {
           elements[i] = s.nextInt();
       }
       Arrays.sort(elements);
       long sum = 0;
       for(int i=0;i<k&&i<size;i++) {
           sum += elements[i];
       }
       System.out.println(sum);
   } main {
       Scanner s = new Scanner(System.in);
       int size = s.nextInt();
       int k = s.nextInt();
       int elements[] = new int[size];
       for(int i=0;i<size;i++) {
           elements[i] = s.nextInt();
       }
       Arrays.sort(elements);
       long sum = 0;
       for(int i=0;i<k&&i<size;i++) {
           sum += elements[i];
       }
       System.out.println(sum);
   } Scanner s = new Scanner(System.in); s new Scanner(System.in) int size = s.nextInt(); size s.nextInt() s.nextInt s int k = s.nextInt(); k s.nextInt() s.nextInt s int elements[] = new int[size]; elements new int[size] size for(int i=0;i<size;i++) {
           elements[i] = s.nextInt();
       } int i=0; int i=0; i 0 i<size i size i++ i++ i {
           elements[i] = s.nextInt();
       } {
           elements[i] = s.nextInt();
       } elements[i] = s.nextInt() elements[i] elements i s.nextInt() s.nextInt s Arrays.sort(elements) Arrays.sort Arrays elements long sum = 0; sum 0 for(int i=0;i<k&&i<size;i++) {
           sum += elements[i];
       } int i=0; int i=0; i 0 i<k&&i<size i<k i k i<size i size i++ i++ i {
           sum += elements[i];
       } {
           sum += elements[i];
       } sum += elements[i] sum elements[i] elements i 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 s = new Scanner(System.in);
       int size = s.nextInt();
       int k = s.nextInt();
       int elements[] = new int[size];
       for(int i=0;i<size;i++) {
           elements[i] = s.nextInt();
       }
       Arrays.sort(elements);
       long sum = 0;
       for(int i=0;i<k&&i<size;i++) {
           sum += elements[i];
       }
       System.out.println(sum);
   }
} public class Main {
   public static void main(String[] args) {
       Scanner s = new Scanner(System.in);
       int size = s.nextInt();
       int k = s.nextInt();
       int elements[] = new int[size];
       for(int i=0;i<size;i++) {
           elements[i] = s.nextInt();
       }
       Arrays.sort(elements);
       long sum = 0;
       for(int i=0;i<k&&i<size;i++) {
           sum += elements[i];
       }
       System.out.println(sum);
   }
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
       Scanner s = new Scanner(System.in);
       int size = s.nextInt();
       int k = s.nextInt();
       int elements[] = new int[size];
       for(int i=0;i<size;i++) {
           elements[i] = s.nextInt();
       }
       Arrays.sort(elements);
       long sum = 0;
       for(int i=0;i<k&&i<size;i++) {
           sum += elements[i];
       }
       System.out.println(sum);
   }
}
