use std::io;
use std::cmp;

fn read_line() -> String {
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("Failed to read line");
    return line;
}
fn to_i(s: &str) -> i32 {
    return s.trim().parse()
        .expect("Please type a number!");
}


fn check(index :u32, xx: &Vec<i32>, val: i32) -> i32 {
    let limit = (xx.len()) as u32;


    if index==limit {
        if val == 0 {
            return 0;
        } else {
            return -1;
        }
        
    }
    let x = xx[index as usize];
    if val < x {
        return check(index + 1, xx, val);
    }else {
        return 1 + check(index + 1, xx, val-x);
        /*
        let r1 = check(index + 1, xx, val);
        let r2 = 1 + check(index + 1, xx, val-x);
        return cmp::max(r1, r2);
        */
    }
    

}
fn main() {

    let l1 = read_line();
    
    let nx: Vec<&str> = l1.split(' ').collect();

    let n: i32 = to_i(nx[0]);
    let x: i32 = to_i(nx[1]);

    let l2 = read_line();
    

    let items: Vec<&str> = l2.split(' ').collect();
    //println!("items:{:?}", items);

    let mut nums: Vec<i32> = Vec::new();

    let mut sum = 0;
    for item in items {
        let num = to_i(item);
        nums.push(num);
        sum += num;
    }
    if sum == x {
        print!("{}", n);
        return;
    }
    nums.sort();
    //nums.reverse();

    //println!("nums:{:?}", nums);

    let mut sum = 0;
    let mut count = 0;
    for i in 0..nums.len() {
        let num = nums[i];
        //println!("{} {} {}", i, sum + num, x);
        if sum + num <= x {
            if i==nums.len()-1 {
                if sum + num == x {
                    count = i+1;
                    sum += num;
                } else{

                }
            } else {
                count = i+1;
                sum += num;
            }
        } else {
            break;
        }
    }
    
    //println!("count:{:?}", count);

    if count >= nums.len() {
        if n==0 {
            count = 0;
        } else {
            count = (n-1) as usize;
        }
    }
/*
    let mut count = check(0, &nums, x);
    if count <0 {
        count = 0;
    }
*/

    print!("{}", count);


}   