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