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

    let rec loop i acc hon =
        let a, b = ab.(i) in
        let d = min b (m - hon) in
        let acc = acc + a * d in
        let hon = hon + d in
        if hon < m then loop (i + 1) acc hon
            else acc
    in
    loop 0 0 0 |> Printf.printf "%d\n"
)