use std::io; use std::io::prelude::*; fn main() { let stdin = io::read_to_string(io::stdin()).unwrap(); let mut stdin = stdin.split_whitespace(); let stdout = io::stdout(); let mut stdout = io::BufWriter::new(stdout.lock()); let l: usize = stdin.next().unwrap().parse::().unwrap(); let n: usize = stdin.next().unwrap().parse::().unwrap(); let mut wn: Vec = vec![198471237812781; 100010]; for i in 0..n { wn[i] = stdin.next().unwrap().parse::().unwrap(); } wn.sort_unstable(); let sequence: Vec<_> = wn.into_iter().scan(0, |state, x| { *state += x; if *state > l { None } else { Some(*state) } }).collect(); writeln!(stdout, "{}", sequence.len()).unwrap_or(()); }