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 sum = 0; int w = 0; for (int i = 0; i < n; i++) { sum += list.get(i); if (sum <= l) { w++; } else { break; } } System.out.println(w); } }