fn main() { let mut l = String::new(); std::io::stdin().read_line(&mut l).expect("Failed to read L"); let mut l: i32 = l.trim().parse().expect("Failed to parse L"); let mut n = String::new(); std::io::stdin().read_line(&mut n).expect("Failed to read N"); let n: i32 = n.trim().parse().expect("Failed to parse N"); let mut w = String::new(); std::io::stdin().read_line(&mut w).expect("Failed to read w"); let mut w: Vec = w.trim().split_whitespace().map(|x| x.parse::().expect("Failed to parse w")).collect::>(); w.sort_unstable(); let mut answer = 0; for ww in w { if l - ww >= 0 { l -= ww; answer+=1; } } println!("{}", answer); }