use std::io; fn main() { let mut n = String::new(); io::stdin().read_line(&mut n).ok(); let mut n: usize = n.trim().parse().unwrap(); let mut m = String::new(); io::stdin().read_line(&mut m).ok(); let m: usize = m.trim().parse().unwrap(); for _ in 0..m { let mut itr = String::new(); io::stdin().read_line(&mut itr).ok(); let mut itr = itr.trim().split_whitespace(); let p: usize = itr.next().unwrap().parse().unwrap(); let q: usize = itr.next().unwrap().parse().unwrap(); if n == p { n = q; } else if n == q { n = p; } else { n = n } } println!("{}", n); }