let rec list_init n f = if n <= 0 then [] else let x = f () in x :: list_init (n-1) f
let step (acc, xs) y =
  match List.filter ((>) y) xs with
  | []       -> (acc, xs)
  | (x::xs') -> (acc+1, List.concat [List.filter ((<) y) xs; xs'])
let () =
  Scanf.scanf "%d" (fun n ->
  let a = list_init n (fun _ -> Scanf.scanf " %d %d" (fun x y -> x, y)) |> List.sort compare in
  let b = list_init n (fun _ -> Scanf.scanf " %d %d" (fun x y -> x, y)) |> List.sort compare in
  b |> List.fold_left step (0, List.rev a)) |> fst |> Printf.printf "%d\n"