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