use std::io::Read; fn main() { let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); let mut l: isize = iter.next().unwrap().parse().unwrap(); let n: usize = iter.next().unwrap().parse().unwrap(); let mut blocks: Vec = iter.map(|b| b.parse::().unwrap()).collect(); blocks.sort(); let mut idx: usize = 0; while idx < n { l -= blocks[idx]; if l < 0 { break } idx += 1; } println!("{}", idx); }