#![allow(unused_imports)] use std::io::{self, BufRead}; use std::str::FromStr; use std::collections::*; use std::cmp::*; struct Parser<'a> { tokens: &'a mut Iterator, } impl<'a> Parser<'a> { fn new(i: &'a mut Iterator) -> Self { Parser {tokens: i} } fn take(&mut self) -> T { match self.tokens.next().expect("empty iterator").parse() { Ok(x) => x, Err(_) => panic!() } } fn take_some(&mut self, n: usize) -> Vec { self.tokens.take(n).map(|s| match s.parse() { Ok(x) => x, Err(_) => panic!() } ).collect() } } fn main() { let stdin = io::stdin(); let mut tokens = stdin.lock().lines().filter_map(|x| x.ok()).flat_map(|x| x.split_whitespace().map(|s| s.to_owned()).collect::>()); let mut parser = Parser::new(&mut tokens); let l: i64 = parser.take(); let n: i64 = parser.take(); let mut w: Vec = parser.take_some(n as usize); w.sort(); let w = w; let mut s = 0i64; let mut ans = 0; for wi in w { s += wi; if s <= l { ans += 1; } } println!("{}", ans); }