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 count = 0; int sum = 0; for (count = 0; count < array2.length; count++) { sum += array2[count]; if (sum > l) break; } System.out.println(count); } }