let unit : int = 0 in

let rec swap : vec[vec[int]] -> int -> int -> int =
  fun (a : vec[vec[int]]) (i : int) (j : int) ->
        if i = j then
          unit
        else
          let t : vec[int] = vector_get a i in
          vector_set a i (vector_get a j);
          vector_set a j t;
          unit
and sort : vec[vec[int]] -> int -> int -> int =
  fun (a : vec[vec[int]]) (p : int) (r : int) ->
    if p < r then
      let q : int = partition a p r in
      sort a p (q - 1) ;
      sort a (q + 1) r ;
      unit
    else
      unit
and mpair_leq : vec[int] -> vec[int] -> bool =
  fun (p1 : vec[int]) (p2 : vec[int]) ->
    let p1_fst : int = vector_get p1 0 in
    let p2_fst : int = vector_get p2 0 in
    if p1_fst < p2_fst then
      true
    else
      (if p1_fst = p2_fst then
        (vector_get p1 1) <= (vector_get p2 1)
      else
        false)
and partition : vec[vec[int]] -> int -> int -> int =
  fun (a : vec[vec[int]]) (p : int) (r : int) ->
    let i : vec[int] = vector 1 (p - 1) in
    let x : vec[int] = vector_get a r in
    for j = p to r do
      if mpair_leq (vector_get a j) x then
          (vector_set i 0 ((vector_get i 0) + 1) ;
          swap a (vector_get i 0) j) ;
          unit
      else
          unit
    done ;
    (swap a ((vector_get i 0) + 1) r) ;
    ((vector_get i 0) + 1)
in

let run_benchmark : int -> int = fun _ : int ->
  let size : int = read_int () in
  let pair : vec[int] = vector 2 0 in
  vector_set pair 0 (read_int ()) ;
  vector_set pair 1 (read_int ()) ;
  (let a : vec[vec[int]] = vector size pair in
  for i = 1 to size do
    let pair : vec[int] = vector 2 0 in
    vector_set pair 0 (read_int ()) ;
    vector_set pair 1 (read_int ()) ;
    vector_set a i pair
  done ;
  sort a 0 (size - 1) ;
  print_int (vector_get (vector_get a 0) 1))
in
(time run_benchmark)
