import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      list.add(sc.nextInt());
    }
    List<Integer> collect = list.stream().sorted().collect(Collectors.toList());
    int sum = 0;
    for (int i = 0; i < k; i++) {
      sum += collect.get(i);
    }
    System.out.println(sum);
  }
} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util import java.util.stream.Collectors; Collectors java.util.stream public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      list.add(sc.nextInt());
    }
    List<Integer> collect = list.stream().sorted().collect(Collectors.toList());
    int sum = 0;
    for (int i = 0; i < k; i++) {
      sum += collect.get(i);
    }
    System.out.println(sum);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      list.add(sc.nextInt());
    }
    List<Integer> collect = list.stream().sorted().collect(Collectors.toList());
    int sum = 0;
    for (int i = 0; i < k; i++) {
      sum += collect.get(i);
    }
    System.out.println(sum);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      list.add(sc.nextInt());
    }
    List<Integer> collect = list.stream().sorted().collect(Collectors.toList());
    int sum = 0;
    for (int i = 0; i < k; i++) {
      sum += collect.get(i);
    }
    System.out.println(sum);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int k = sc.nextInt(); k sc.nextInt() sc.nextInt sc List<Integer> list = new ArrayList<>(); list new ArrayList<>() for (int i = 0; i < n; i++) {
      list.add(sc.nextInt());
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      list.add(sc.nextInt());
    } {
      list.add(sc.nextInt());
    } list.add(sc.nextInt()) list.add list sc.nextInt() sc.nextInt sc List<Integer> collect = list.stream().sorted().collect(Collectors.toList()); collect list.stream().sorted().collect(Collectors.toList()) list.stream().sorted().collect list.stream().sorted() list.stream().sorted list.stream() list.stream list Collectors.toList() Collectors.toList Collectors int sum = 0; sum 0 for (int i = 0; i < k; i++) {
      sum += collect.get(i);
    } int i = 0; int i = 0; i 0 i < k i k i++ i++ i {
      sum += collect.get(i);
    } {
      sum += collect.get(i);
    } sum += collect.get(i) sum collect.get(i) collect.get collect 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 sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      list.add(sc.nextInt());
    }
    List<Integer> collect = list.stream().sorted().collect(Collectors.toList());
    int sum = 0;
    for (int i = 0; i < k; i++) {
      sum += collect.get(i);
    }
    System.out.println(sum);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      list.add(sc.nextInt());
    }
    List<Integer> collect = list.stream().sorted().collect(Collectors.toList());
    int sum = 0;
    for (int i = 0; i < k; i++) {
      sum += collect.get(i);
    }
    System.out.println(sum);
  }
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      list.add(sc.nextInt());
    }
    List<Integer> collect = list.stream().sorted().collect(Collectors.toList());
    int sum = 0;
    for (int i = 0; i < k; i++) {
      sum += collect.get(i);
    }
    System.out.println(sum);
  }
}
