#[allow(dead_code)] mod cc { pub fn read_line() -> Option { let mut buf = String::new(); let len = std::io::stdin().read_line(&mut buf).ok(); if let Some(0) = len { None } else { Some(buf.trim().to_string()) } } pub fn parse_to(s: String) -> T { s.trim().parse().ok().unwrap() } pub fn drop_line() { read_line(); } } fn read_data() -> (u8, Vec<[u8; 2]>) { let n: u8 = cc::parse_to(cc::read_line().unwrap()); cc::drop_line(); let mut vs: Vec<[u8; 2]> = Vec::new(); while let Some(_s) = cc::read_line() { let _v: Vec = _s .split_ascii_whitespace() .map(|e| e.parse().ok().unwrap()) .collect(); vs.push([_v[0], _v[1]]); } (n, vs) } fn calc(n: u8, v: Vec<[u8; 2]>) -> u8 { let mut now = n; for [left, right] in v { if now == left { now = right; } else if now == right { now = left; } } now } fn main() { let (n, v) = read_data(); println!("{}", calc(n, v)); }