import java.util.Arrays; import java.util.Scanner; public class Yuki1 { public static void main(String[] argas) { Scanner scan = new Scanner(System.in); // 箱の幅 int box = scan.nextInt(); // ブロックの数 int blockCount = scan.nextInt(); int[] blockWidth = new int [blockCount]; for (int i = 0; i < blockWidth.length; i++) { blockWidth[i] = scan.nextInt(); } Arrays.sort(blockWidth); int boxWidthAll = 0; int boxWidthAllCount = 0; for (int i = 0; i < blockWidth.length; i++) { boxWidthAll = boxWidthAll + blockWidth[i]; if ( box < boxWidthAll) { break; } boxWidthAllCount++; } System.out.println(boxWidthAllCount); } }