use std::io;
use std::io::{Stdin, BufRead};


struct Input {
    l: u32,
    n: u32,
    w: Vec<u32>,
}


fn main() {
    let mut stdin = io::stdin();
    let input = read_input(&mut stdin);
    let mut w = input.w;
    w.sort();
    let mut count = 0;
    let mut sum = 0;
    for e in w {
        sum += e;
        if input.l < sum {
            break;
        }
        count += 1;
    }
    println!("{}", count);
}


fn read_input(stdin: &mut Stdin) -> Input {
    let l: u32 = read_single();
    let n: u32 = read_single();
    let mut w: Vec<u32> = read_vec();

    Input { l, n, w }
}

fn read_single<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_single::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}