use std::collections::{BTreeMap}; use std::io::*; use std::str::*; fn read(sl: &mut StdinLock) -> Option { let s = sl.by_ref().bytes().map(|c| c.unwrap() as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect::(); s.parse::().ok() } fn run(sl: &mut StdinLock) { let l = read::(sl).unwrap(); let n = read::(sl).unwrap(); let mut t = BTreeMap::new(); for _ in 0..n { let w = read::(sl).unwrap(); let mut wn = 0; { let t = &t; if let Some(_wn) = t.get(&w) { wn = *_wn; } } t.insert(w, wn + 1); } let mut rl = 0; let mut rn = 0; for (w, wn) in t.iter() { let wl = w * wn; if rl + wl > l { rn += (l - rl) / w; break; } else { rl += wl; rn += wn; } } println!("{}", rn); } fn main() { let s = stdin(); let mut sl = s.lock(); run(&mut sl); }