fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } fn main() { let mut space: i32 = read(); let num: i32 = read(); let mut blocks: Vec = read_vec(); blocks.sort(); let mut count = 0; for i in 0..=(num as usize) { space = space - blocks[i]; if (space < 0) { break; } count += 1; } println!("{}", count); }