use std::io::*; //use std::num; use std::str::FromStr; //use std::time::Instant; fn main() { //let now = Instant::now(); let n: u64 = read(); let m: usize = read(); let mut a = vec![0; m]; let mut count: u64 = 0; let mut tmp; for _i in 0..a.len(){ a[_i] = read(); } for _j in 0..a.len()-1{ for _i in 0..a.len()-1{ if a[_i] > a[_i + 1]{ tmp = a[_i]; a[_i] = a[_i + 1]; a[_i + 1] = tmp; } } } /* for _i in 0..a.len(){ println!("{}",a[_i]); } */ for _i in 0..=a.len(){ if count < n && _i == a.len(){ println!("{}",_i); break; }else if count == n{ println!("{}",_i); break; }else if count >= n{ println!("{}",_i-1); break; } count += a[_i]; } //println!("[DEBUG_PRINT] {} ms", now.elapsed().as_millis()); } pub fn min(x: usize, y: usize) -> usize { let z: usize; if x <= y { z = x; } else { z = y; } return z; } pub fn read() -> T { let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") } pub fn read_array() -> Vec { let array: String = read(); let chars: Vec = array.trim().chars().collect::>(); chars } pub fn get_data() -> Vec { let mut s: String = String::new(); std::io::stdin().read_line(&mut s).ok(); let vec: Vec = s .trim() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect(); vec } pub fn get_chars() -> Vec { let mut s: String = String::new(); std::io::stdin().read_line(&mut s).ok(); let vec: Vec = s.trim().chars().collect::>(); vec }