// let L, N, W; // process.stdin.resume(); process.stdin.setEncoding('utf8'); process.stdin.on('data', data => { const arr = data.split('\n'); L = Number(arr[0]); N = Number(arr[1]); W = arr[2].split(' ').map(x => Number(x)); }); process.stdin.on('end', () => { let dp0 = new Array(L + 1).fill(0); let dp1 = new Array(L + 1).fill(0); for (let i = 0; i < N; i++) { [dp0, dp1] = [dp1, dp0]; dp1.fill(0); for (let j = 0; j <= L; j++) { if (j < W[i]) { dp1[j] = dp0[j]; } else { dp1[j] = Math.max(dp0[j], dp0[j - W[i]] + 1); } } } console.log(Math.max(dp1[L])); });