import java.util.Scanner; public class yukicoder_5 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String str_l = scanner.nextLine(); int l = Integer.parseInt(str_l); String str_n = scanner.nextLine(); int n = Integer.parseInt(str_n); String w = scanner.nextLine(); String[] array = w.split(" "); int[] array2 = new int[array.length]; for (int i = 0; i < array.length; i++) { array2[i] = Integer.parseInt(array[i]); } for (int j = 0; j < array2.length; j++) { for (int i = 0; i < array2.length - 1; i++) { if (array2[i] > array2[i+1]) { int t; t = array2[i]; array2[i] = array2[i+1]; array2[i+1] = t; } } } int block = 0; int sum = 0; for (block = 0; sum < l; block++) { sum += array2[block]; } System.out.println(block - 1); } }