import java.util.Scanner; import java.util.List; import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int l = sc.nextInt(); int n = sc.nextInt(); List list = new ArrayList<>(); for (int i = 0; i < n; i++) { list.add(sc.nextInt()); } Collections.sort(list); int i3 = 0; for (int w = 0; w < n; w++) { i3 += list.get(w); if (i3 >= l) { System.out.println(w); break; } } } }