import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class No5 { /** * @param args * @throws IOException * @throws NumberFormatException */ public static void main(String[] args) throws NumberFormatException, IOException { int boxLength; // inputの準備 BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); boxLength = Integer.parseInt(br.readLine()); br.readLine(); String[] blockLengthStringList = br.readLine().split(" "); int[] blockLengthList = new int[blockLengthStringList.length]; for(int i=0; i < blockLengthStringList.length; i++) { blockLengthList[i] = Integer.parseInt(blockLengthStringList[i]); } Arrays.sort(blockLengthList); // ボックスに最大何個入れられるかを計算 int insertNum = -1; int sumLength = 0; for(int i = 0; sumLength < boxLength; i++) { sumLength += blockLengthList[i]; insertNum++; } System.out.println(insertNum); } }