let () = Scanf.scanf "%d %d\n" @@ fun w h ->
  let ps = Array.init w (fun _ -> Scanf.scanf "%d\n" (fun p -> (p, `P))) in
  let qs = Array.init h (fun _ -> Scanf.scanf "%d\n" (fun q -> (q, `Q))) in
  List.sort compare (Array.to_list qs @ Array.to_list ps)
  |> List.fold_left (fun (cost, (w, h)) -> function
    | (p, `P) ->
        (* p_i は，∀j. (i, j)と(i + 1, j)を結ぶコスト *)
        (cost + p * h, (w - 1, h))
    | (q, `Q) ->
        (* q_j は，∀i. (i, j)と(i, j + 1)を結ぶコスト *)
        (cost + q * w, (w, h - 1))) (0, (w + 1, h + 1))
  |> fst
  |> Printf.printf "%d\n"