
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		//オブジェクト生成
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		ArrayList<Integer> minNumList = new ArrayList<Integer>();

		//代入作業
		int num1 = scan.nextInt();
		int buyCnt = scan.nextInt();
		for (int i = 0; i < num1; i++) {
			list.add(scan.nextInt());
		}

		int minNum = 0;
		int[] minNumArray = new int[buyCnt];
		for (int j = 0; j < buyCnt; j++) {
			minNum = list.get(0);
			for (int i = 1; i < num1 - j; i++) {
				if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				}
			}
			minNumArray[j] = minNum;
			list.remove(list.indexOf(minNum));
		}

		int ans = 0;
		for (int i = 0; i < minNumArray.length; i++) {
			ans += minNumArray[i];
		}

		System.out.println(ans);

	}

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

	public static void main(String[] args) {

		//オブジェクト生成
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		ArrayList<Integer> minNumList = new ArrayList<Integer>();

		//代入作業
		int num1 = scan.nextInt();
		int buyCnt = scan.nextInt();
		for (int i = 0; i < num1; i++) {
			list.add(scan.nextInt());
		}

		int minNum = 0;
		int[] minNumArray = new int[buyCnt];
		for (int j = 0; j < buyCnt; j++) {
			minNum = list.get(0);
			for (int i = 1; i < num1 - j; i++) {
				if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				}
			}
			minNumArray[j] = minNum;
			list.remove(list.indexOf(minNum));
		}

		int ans = 0;
		for (int i = 0; i < minNumArray.length; i++) {
			ans += minNumArray[i];
		}

		System.out.println(ans);

	}

} Main public static void main(String[] args) {

		//オブジェクト生成
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		ArrayList<Integer> minNumList = new ArrayList<Integer>();

		//代入作業
		int num1 = scan.nextInt();
		int buyCnt = scan.nextInt();
		for (int i = 0; i < num1; i++) {
			list.add(scan.nextInt());
		}

		int minNum = 0;
		int[] minNumArray = new int[buyCnt];
		for (int j = 0; j < buyCnt; j++) {
			minNum = list.get(0);
			for (int i = 1; i < num1 - j; i++) {
				if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				}
			}
			minNumArray[j] = minNum;
			list.remove(list.indexOf(minNum));
		}

		int ans = 0;
		for (int i = 0; i < minNumArray.length; i++) {
			ans += minNumArray[i];
		}

		System.out.println(ans);

	} main {

		//オブジェクト生成
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		ArrayList<Integer> minNumList = new ArrayList<Integer>();

		//代入作業
		int num1 = scan.nextInt();
		int buyCnt = scan.nextInt();
		for (int i = 0; i < num1; i++) {
			list.add(scan.nextInt());
		}

		int minNum = 0;
		int[] minNumArray = new int[buyCnt];
		for (int j = 0; j < buyCnt; j++) {
			minNum = list.get(0);
			for (int i = 1; i < num1 - j; i++) {
				if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				}
			}
			minNumArray[j] = minNum;
			list.remove(list.indexOf(minNum));
		}

		int ans = 0;
		for (int i = 0; i < minNumArray.length; i++) {
			ans += minNumArray[i];
		}

		System.out.println(ans);

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) ArrayList<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() ArrayList<Integer> minNumList = new ArrayList<Integer>(); minNumList new ArrayList<Integer>() int num1 = scan.nextInt(); num1 scan.nextInt() scan.nextInt scan int buyCnt = scan.nextInt(); buyCnt scan.nextInt() scan.nextInt scan for (int i = 0; i < num1; i++) {
			list.add(scan.nextInt());
		} int i = 0; int i = 0; i 0 i < num1 i num1 i++ i++ i {
			list.add(scan.nextInt());
		} {
			list.add(scan.nextInt());
		} list.add(scan.nextInt()) list.add list scan.nextInt() scan.nextInt scan int minNum = 0; minNum 0 int[] minNumArray = new int[buyCnt]; minNumArray new int[buyCnt] buyCnt for (int j = 0; j < buyCnt; j++) {
			minNum = list.get(0);
			for (int i = 1; i < num1 - j; i++) {
				if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				}
			}
			minNumArray[j] = minNum;
			list.remove(list.indexOf(minNum));
		} int j = 0; int j = 0; j 0 j < buyCnt j buyCnt j++ j++ j {
			minNum = list.get(0);
			for (int i = 1; i < num1 - j; i++) {
				if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				}
			}
			minNumArray[j] = minNum;
			list.remove(list.indexOf(minNum));
		} {
			minNum = list.get(0);
			for (int i = 1; i < num1 - j; i++) {
				if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				}
			}
			minNumArray[j] = minNum;
			list.remove(list.indexOf(minNum));
		} minNum = list.get(0) minNum list.get(0) list.get list 0 for (int i = 1; i < num1 - j; i++) {
				if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				}
			} int i = 1; int i = 1; i 1 i < num1 - j i num1 - j num1 j i++ i++ i {
				if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				}
			} {
				if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				}
			} if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				} minNum < list.get(i) minNum list.get(i) list.get list i {
					//何もしない
				} {
					minNum = list.get(i);
				} minNum = list.get(i) minNum list.get(i) list.get list i minNumArray[j] = minNum minNumArray[j] minNumArray j minNum list.remove(list.indexOf(minNum)) list.remove list list.indexOf(minNum) list.indexOf list minNum int ans = 0; ans 0 for (int i = 0; i < minNumArray.length; i++) {
			ans += minNumArray[i];
		} int i = 0; int i = 0; i 0 i < minNumArray.length i minNumArray.length minNumArray minNumArray.length i++ i++ i {
			ans += minNumArray[i];
		} {
			ans += minNumArray[i];
		} ans += minNumArray[i] ans minNumArray[i] minNumArray i System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

	public static void main(String[] args) {

		//オブジェクト生成
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		ArrayList<Integer> minNumList = new ArrayList<Integer>();

		//代入作業
		int num1 = scan.nextInt();
		int buyCnt = scan.nextInt();
		for (int i = 0; i < num1; i++) {
			list.add(scan.nextInt());
		}

		int minNum = 0;
		int[] minNumArray = new int[buyCnt];
		for (int j = 0; j < buyCnt; j++) {
			minNum = list.get(0);
			for (int i = 1; i < num1 - j; i++) {
				if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				}
			}
			minNumArray[j] = minNum;
			list.remove(list.indexOf(minNum));
		}

		int ans = 0;
		for (int i = 0; i < minNumArray.length; i++) {
			ans += minNumArray[i];
		}

		System.out.println(ans);

	}

} public class Main {

	public static void main(String[] args) {

		//オブジェクト生成
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		ArrayList<Integer> minNumList = new ArrayList<Integer>();

		//代入作業
		int num1 = scan.nextInt();
		int buyCnt = scan.nextInt();
		for (int i = 0; i < num1; i++) {
			list.add(scan.nextInt());
		}

		int minNum = 0;
		int[] minNumArray = new int[buyCnt];
		for (int j = 0; j < buyCnt; j++) {
			minNum = list.get(0);
			for (int i = 1; i < num1 - j; i++) {
				if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				}
			}
			minNumArray[j] = minNum;
			list.remove(list.indexOf(minNum));
		}

		int ans = 0;
		for (int i = 0; i < minNumArray.length; i++) {
			ans += minNumArray[i];
		}

		System.out.println(ans);

	}

} Main

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		//オブジェクト生成
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		ArrayList<Integer> minNumList = new ArrayList<Integer>();

		//代入作業
		int num1 = scan.nextInt();
		int buyCnt = scan.nextInt();
		for (int i = 0; i < num1; i++) {
			list.add(scan.nextInt());
		}

		int minNum = 0;
		int[] minNumArray = new int[buyCnt];
		for (int j = 0; j < buyCnt; j++) {
			minNum = list.get(0);
			for (int i = 1; i < num1 - j; i++) {
				if (minNum < list.get(i)) {
					//何もしない
				} else {
					minNum = list.get(i);
				}
			}
			minNumArray[j] = minNum;
			list.remove(list.indexOf(minNum));
		}

		int ans = 0;
		for (int i = 0; i < minNumArray.length; i++) {
			ans += minNumArray[i];
		}

		System.out.println(ans);

	}

}
