use std::io::{self, BufReader, BufWriter, Read, Write}; fn main() { let stdin = io::stdin(); let mut stdin = BufReader::new(stdin.lock()); let stdout = io::stdout(); let mut stdout = BufWriter::new(stdout.lock()); let mut buf = String::new(); stdin.read_to_string(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); let l: u32 = iter.next().unwrap().parse().unwrap(); let n: usize = iter.next().unwrap().parse().unwrap(); let mut w: Vec = iter.take(n).map(|s| s.parse::().unwrap()).collect(); w.sort(); let mut sum = 0; for (i, x) in w.into_iter().enumerate() { sum += x; if sum > l { writeln!(&mut stdout, "{}", i).unwrap(); return; } } writeln!(&mut stdout, "{}", n).unwrap(); }