import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int boxWidth = sc.nextInt(); int numBlock = sc.nextInt(); List blockWidthList = new ArrayList(); for (int i = 0; i < numBlock; i++) { blockWidthList.add(sc.nextInt()); } Collections.sort(blockWidthList); int count = 0; int filledWidth = 0; for (Integer width : blockWidthList) { filledWidth += width; if (filledWidth > boxWidth) { break; } count++; } System.out.println(count); } }