let move_cur cur side =
    match side with
    | (a, b) when cur = a -> b
    | (a, b) when cur = b -> a
    | _                   -> cur

let () =
    let n_lines = read_int () in
    let n_sides = read_int () in

    let sides = Array.make n_sides (0, 0) in
    for i = 0 to n_sides-1 do
        let side = Scanf.scanf "%d,%d\n" (fun a b -> (a, b)) in
        sides.(i) <- side
    done ;

    let starts = Array.make n_lines 0 in
    for start = 1 to n_lines do
        let last = Array.fold_left move_cur start sides in
        starts.(last-1) <- start
    done ;

    Array.iter (Printf.printf "%d\n") starts