import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int n=Integer.parseInt(line[0]);
        int k=Integer.parseInt(line[1]);

        String[] line1 = sc.nextLine().split(" ");
    
        int[] num=new int[n];
        for(int i=0;i<n;i++){
          num[i]=Integer.parseInt(line1[i]);
        }

        List<Integer> list=new ArrayList<Integer>();

        for(int i=0;i<k;i++){
          list.add(num[i]);
        } 
        for(int i=k;i<n;i++){
          if(num[i]<Collections.max(list)){
            list.add(num[i]);
            list.remove(Collections.max(list));
          }
        }
        int sum=0;

        for(int value:list){
          sum=sum+value;
        }

          System.out.println(sum);
    }
  
}

 import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int n=Integer.parseInt(line[0]);
        int k=Integer.parseInt(line[1]);

        String[] line1 = sc.nextLine().split(" ");
    
        int[] num=new int[n];
        for(int i=0;i<n;i++){
          num[i]=Integer.parseInt(line1[i]);
        }

        List<Integer> list=new ArrayList<Integer>();

        for(int i=0;i<k;i++){
          list.add(num[i]);
        } 
        for(int i=k;i<n;i++){
          if(num[i]<Collections.max(list)){
            list.add(num[i]);
            list.remove(Collections.max(list));
          }
        }
        int sum=0;

        for(int value:list){
          sum=sum+value;
        }

          System.out.println(sum);
    }
  
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int n=Integer.parseInt(line[0]);
        int k=Integer.parseInt(line[1]);

        String[] line1 = sc.nextLine().split(" ");
    
        int[] num=new int[n];
        for(int i=0;i<n;i++){
          num[i]=Integer.parseInt(line1[i]);
        }

        List<Integer> list=new ArrayList<Integer>();

        for(int i=0;i<k;i++){
          list.add(num[i]);
        } 
        for(int i=k;i<n;i++){
          if(num[i]<Collections.max(list)){
            list.add(num[i]);
            list.remove(Collections.max(list));
          }
        }
        int sum=0;

        for(int value:list){
          sum=sum+value;
        }

          System.out.println(sum);
    } main {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int n=Integer.parseInt(line[0]);
        int k=Integer.parseInt(line[1]);

        String[] line1 = sc.nextLine().split(" ");
    
        int[] num=new int[n];
        for(int i=0;i<n;i++){
          num[i]=Integer.parseInt(line1[i]);
        }

        List<Integer> list=new ArrayList<Integer>();

        for(int i=0;i<k;i++){
          list.add(num[i]);
        } 
        for(int i=k;i<n;i++){
          if(num[i]<Collections.max(list)){
            list.add(num[i]);
            list.remove(Collections.max(list));
          }
        }
        int sum=0;

        for(int value:list){
          sum=sum+value;
        }

          System.out.println(sum);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] line = sc.nextLine().split(" "); line sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int n=Integer.parseInt(line[0]); n Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 int k=Integer.parseInt(line[1]); k Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 String[] line1 = sc.nextLine().split(" "); line1 sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int[] num=new int[n]; num new int[n] n for(int i=0;i<n;i++){
          num[i]=Integer.parseInt(line1[i]);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
          num[i]=Integer.parseInt(line1[i]);
        } {
          num[i]=Integer.parseInt(line1[i]);
        } num[i]=Integer.parseInt(line1[i]) num[i] num i Integer.parseInt(line1[i]) Integer.parseInt Integer line1[i] line1 i List<Integer> list=new ArrayList<Integer>(); list new ArrayList<Integer>() for(int i=0;i<k;i++){
          list.add(num[i]);
        } int i=0; int i=0; i 0 i<k i k i++ i++ i {
          list.add(num[i]);
        } {
          list.add(num[i]);
        } list.add(num[i]) list.add list num[i] num i for(int i=k;i<n;i++){
          if(num[i]<Collections.max(list)){
            list.add(num[i]);
            list.remove(Collections.max(list));
          }
        } int i=k; int i=k; i k i<n i n i++ i++ i {
          if(num[i]<Collections.max(list)){
            list.add(num[i]);
            list.remove(Collections.max(list));
          }
        } {
          if(num[i]<Collections.max(list)){
            list.add(num[i]);
            list.remove(Collections.max(list));
          }
        } if(num[i]<Collections.max(list)){
            list.add(num[i]);
            list.remove(Collections.max(list));
          } num[i]<Collections.max(list) num[i] num i Collections.max(list) Collections.max Collections list {
            list.add(num[i]);
            list.remove(Collections.max(list));
          } list.add(num[i]) list.add list num[i] num i list.remove(Collections.max(list)) list.remove list Collections.max(list) Collections.max Collections list int sum=0; sum 0 for(int value:list){
          sum=sum+value;
        } int value list {
          sum=sum+value;
        } {
          sum=sum+value;
        } sum=sum+value sum sum+value sum value 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);
        String[] line = sc.nextLine().split(" ");
        int n=Integer.parseInt(line[0]);
        int k=Integer.parseInt(line[1]);

        String[] line1 = sc.nextLine().split(" ");
    
        int[] num=new int[n];
        for(int i=0;i<n;i++){
          num[i]=Integer.parseInt(line1[i]);
        }

        List<Integer> list=new ArrayList<Integer>();

        for(int i=0;i<k;i++){
          list.add(num[i]);
        } 
        for(int i=k;i<n;i++){
          if(num[i]<Collections.max(list)){
            list.add(num[i]);
            list.remove(Collections.max(list));
          }
        }
        int sum=0;

        for(int value:list){
          sum=sum+value;
        }

          System.out.println(sum);
    }
  
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int n=Integer.parseInt(line[0]);
        int k=Integer.parseInt(line[1]);

        String[] line1 = sc.nextLine().split(" ");
    
        int[] num=new int[n];
        for(int i=0;i<n;i++){
          num[i]=Integer.parseInt(line1[i]);
        }

        List<Integer> list=new ArrayList<Integer>();

        for(int i=0;i<k;i++){
          list.add(num[i]);
        } 
        for(int i=k;i<n;i++){
          if(num[i]<Collections.max(list)){
            list.add(num[i]);
            list.remove(Collections.max(list));
          }
        }
        int sum=0;

        for(int value:list){
          sum=sum+value;
        }

          System.out.println(sum);
    }
  
} Main
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int n=Integer.parseInt(line[0]);
        int k=Integer.parseInt(line[1]);

        String[] line1 = sc.nextLine().split(" ");
    
        int[] num=new int[n];
        for(int i=0;i<n;i++){
          num[i]=Integer.parseInt(line1[i]);
        }

        List<Integer> list=new ArrayList<Integer>();

        for(int i=0;i<k;i++){
          list.add(num[i]);
        } 
        for(int i=k;i<n;i++){
          if(num[i]<Collections.max(list)){
            list.add(num[i]);
            list.remove(Collections.max(list));
          }
        }
        int sum=0;

        for(int value:list){
          sum=sum+value;
        }

          System.out.println(sum);
    }
  
}


