Scanf.scanf "%d %d" (fun n x ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort compare a;

    let rec loop i acc =
        if i = n then (if acc = x then i else i - 1) else
            if acc + a.(i) <= x then loop (i + 1) (acc + a.(i)) else i
    in
    loop 0 0 |> Printf.printf "%d\n"
)