function Main(input) {
    var line = input.split("\n");
    var L = +line[0];
    var N = +line[1];
    var W = line[2].split(" ").map(Number);

    rapt(L, N, W);
}

function rapt(L, N, W) {
    var widthSum = 0;
    var countBox = 0;

    W.sort(function (a, b) {
        if (a < b) return -1;
        if (a > b) return 1;
        return 0;
    });

    for (var i = 0; widthSum <= L; i++) {
        widthSum += W[i];
        countBox += 1;
    }
    if (widthSum == L) {
        console.log(countBox);
    } else {
        console.log(countBox - 1);
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));