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; while(box>boxWidthAll && blockCount>boxWidthAllCount){ boxWidthAll +=blockWidth[boxWidthAllCount]; if(box>boxWidthAll) { boxWidthAllCount++; } } System.out.println(boxWidthAllCount); } }