let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let abs = Array.init n @@ fun _ -> Scanf.scanf "%d %d\n" @@ fun a b -> a, b in
  Array.sort (fun (a, _) (a', _) -> compare a a') abs;
  Printf.printf "%d\n" @@ fst @@ Array.fold_left (fun (acc, n) (a, b) ->
    (acc + a * min n b, n - min n b)) (0, m) abs
