use std::io::{Read,stdin}; fn main() { let mut buf = String::new(); stdin().read_to_string(&mut buf).unwrap(); let mut tok = buf.split_whitespace(); let mut get = || tok.next().unwrap(); let n = get().as_bytes(); let m = get().as_bytes(); let mut cnt = 0; for &ch in n.iter() { let p = (ch - b'0') as i64; cnt += p; } let nl = (n[n.len()-1] - b'0') as i64; let mut rn = 0; for i in -1..2 { let x = cnt + i; if x % 3 == 0 { let y = nl + i + 2; if y % 2 == 0 { rn = (6 - i) % 6; } else { rn = 3 - i; } } } //println!("{}", rn); let ml = (m[m.len()-1] - b'0') as i64; let ans = match (rn, ml % 2) { (2,0) => 4, (5,0) => 1, (rn,_) => rn, }; let ans = (ans + 5) % 6; println!("{}", b"285714"[ans as usize] as char); }