use std::str::FromStr; const DX: [i32; 8] = [0, 1, 0, -1, 1, 1, -1, -1]; const DY: [i32; 8] = [1, 0, -1, 0, 1, -1, -1, 1]; fn main() { let (r, w) = (std::io::stdin(), std::io::stdout()); let mut sc = IO::new(r.lock(), w.lock()); let l: i64 = sc.read(); let n: usize = sc.read(); let mut a: Vec = sc.vec(n); a.sort(); let mut now = l; let mut cnt = 0; for x in a { if now - x < 0 { break; } now -= x; cnt += 1; } println!("{}", cnt); } pub struct IO(R, std::io::BufWriter); impl IO { pub fn new(r: R, w: W) -> Self { Self(r, std::io::BufWriter::new(w)) } pub fn write(&mut self, s: S) { use std::io::Write; self.1.write_all(s.to_string().as_bytes()).unwrap(); } pub fn read(&mut self) -> T { use std::io::Read; let buf = self.0.by_ref().bytes() .map(|b| b.unwrap()) .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t') .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t') .collect::>(); unsafe { std::str::from_utf8_unchecked(&buf) }.parse().ok().expect("Parse error.") } pub fn chars(&mut self) -> Vec { self.read::().chars().collect() } pub fn usize0(&mut self) -> usize { self.read::() - 1 } pub fn vec(&mut self, n: usize) -> Vec { (0..n).map(|_| self.read()).collect() } }