import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.stream.Stream; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // L int numL = Integer.parseInt(br.readLine()); // N int numN = Integer.parseInt(br.readLine()); // W1,W2,,,,,Wn int[] numW = Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).sorted().toArray(); int sum = 0; int count = 0; for (int num : numW) { sum += num; if (sum > numL) break; else count++; } System.out.println(count); } }