let stream_fold f stream init = let result = ref init in Stream.iter (fun x -> result := f !result x) stream; !result let swap curPos (p, q) = match curPos = p, curPos = q with | true, false -> q | false, true -> p | _, _ -> curPos let () = let n = read_line () |> int_of_string and m = read_line () |> int_of_string in let inSeq = Stream.from (fun i -> if i < m then read_line () |> Str.split (Str.regexp_string " ") |> List.map int_of_string |> fun lst -> Some (List.nth lst 0, List.nth lst 1) else None) in stream_fold swap inSeq n |> string_of_int |> print_endline