import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        // System.out.println("Hello World");
        // 入力を受け取る
        Scanner scan = new Scanner(System.in);
        String strL = scan.nextLine();
        String strN = scan.nextLine();
        String strW = scan.nextLine();
        scan.close();
        // 値を受け取る
        int l = Integer.parseInt(strL);
        int n = Integer.parseInt(strN);
        String[] arrW = strW.split(" ");
        int[] w = new int[arrW.length];
        for(int i = 0; i < arrW.length; i++) {
            w[i] = Integer.parseInt(arrW[i]);
        }
        // System.out.println(l);
        // System.out.println(n);
        // for(int i = 0; i < w.length; i++) {
        //     System.out.println(w[i]);
        // }
        
        
        // 計算
            //必要な変数
                // L’
                int lBox = 0;
                // count
                int count = 0;
            Arrays.sort(w);
            // for(int i = 0; i < w.length; i++) {
            // System.out.println(w[i]);
            // }
            // ループ開始
            for (int i = 0; i < w.length; i++) {
            // ソートしたW’を小さい順にL’に足していく
                lBox += w[i];
            // L<L’になったときループ終了
                if(l < lBox) {
                    break;
                }
            // countに1を足す
                count ++;
            }
        // 出力
            // countを出力
            System.out.println(count);
    }
}