use std::{ io::{self, BufRead}, process::exit, }; fn main() { let lines = io::stdin() .lock() .lines() .map(std::result::Result::unwrap) .collect::>(); let length = lines[0].parse::().unwrap(); let mut widths = lines[2] .split(' ') .map(|w| w.parse::().unwrap()) .collect::>(); widths.sort_unstable(); let mut i = 0; let mut sum = 0; while i < widths.len() { sum += widths[i]; if sum > length { println!("{}", i); exit(0); } i += 1; } println!("{}", i); }