package coder; import java.util.Arrays; import java.util.Scanner; public class No5 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int width = scanner.nextInt(); int num = scanner.nextInt(); int[] blockWidth = new int[num]; for(int i = 0; i < num; i++) { blockWidth[i] = scanner.nextInt(); } Arrays.sort(blockWidth); int sum = 0; int maxNum = 0; for(int i = 0; i < num; i++) { sum += blockWidth[i]; if(sum > width) { break; } maxNum++; } System.out.println(maxNum); scanner.close(); } }