use std::io::{self, BufRead}; fn main() { let input = io::stdin() .lock() .lines() .map(|l| { l.unwrap() .split(' ') .map(|n| n.parse::().unwrap()) .collect::>() }) .collect::>(); let mut cups = vec![false; 4]; cups[input[0][0]] = true; for i in &input[2..] { cups.swap(i[0], i[1]); } println!("{}", cups.iter().position(|&c| c).unwrap()); }