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

    let amax = Array.fold_left (fun acc (_, a) -> max acc a) 0 ab in

    let phase2 damage count =
        Printf.printf "%d\n" @@ count + (h - damage + amax - 1) / amax
    in

    let rec loop i damage count =
        if i = n then phase2 damage count else
            let (b, _) = ab.(i) in
            let damage, count = if -b >= amax then damage - b, count + 1
                                              else damage, count
            in
            if damage >= h then Printf.printf "%d\n" count else
                loop (i + 1) damage count
    in
    loop 0 0 0
)