import java.io.*; import java.util.Arrays; public class Main01 { public static void main(String[] args) { try { InputStreamReader inputStreamReader = new InputStreamReader(System.in); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); String strBoxLength = bufferedReader.readLine(); int boxLength = Integer.parseInt(strBoxLength); String strBlockNum = bufferedReader.readLine(); int blockNum = Integer.parseInt(strBlockNum); String strBoxsWidth = bufferedReader.readLine(); String[] strBoxWidths = strBoxsWidth.split(" "); int[] boxWidths = new int[strBoxWidths.length]; for (int i = 0; i < blockNum; i++) { boxWidths[i] = Integer.parseInt(strBoxWidths[i]); } // ソート Arrays.sort(boxWidths); int width = 0; // 幅 int boxNum = 0; // 箱の個数 for (int i = 0; i < strBoxWidths.length; i++) { if (width + boxWidths[i] > boxLength) { boxNum = i; break; } width += boxWidths[i]; } // 結果出力 System.out.println(boxNum); } catch (Throwable th) { th.printStackTrace(); } } }