function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var n = parseInt(input[0][0], 10);
    var m = parseInt(input[0][1], 10);
    var v_price = [];
    var arr_dp = [Array.from({length: n + 1}, () => Number.MAX_SAFE_INTEGER)];
    arr_dp[0][0] = 0;
    var tmp;
    for (var i = 0; i < m; i++){
        v_price.push(parseInt(input[1][i]));
        tmp = v_price[i];
        arr_dp.push([]);
        for (var j = 0; j <= n; j++){
            if (j < tmp) arr_dp[i + 1].push(arr_dp[i][j]);
            if (j >= tmp){
                arr_dp[i + 1].push(Math.min(arr_dp[i][j], arr_dp[i + 1][j - tmp] + 1));
            }
        }
    }
    console.log(arr_dp[m][n]);
}

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