Scanf.scanf "%d %d" (fun n m -> let rec loop i c = if i = m then c else let c = Scanf.scanf " %d %d" (fun p q -> if p = c then q else if q = c then p else c ) in loop (i + 1) c in loop 0 n |> Printf.printf "%d\n" )