fn main() { let mut n = String::new(); std::io::stdin().read_line(&mut n).ok(); let n = n.trim().chars().collect::>(); let mut k = String::new(); std::io::stdin().read_line(&mut k).ok(); let k = k.trim().chars().collect::>(); let mut nval = 0usize; for i in 0..n.len() { nval += n[i] as usize - '0' as usize; nval %= 6; if n.len() == i + 1 { break; } nval *= 10; } match nval { 0 => { println!("4"); }, 1 => { println!("2"); }, 2 => { println!("{}", if (k[k.len()-1] as usize - '0' as usize) % 2 == 0 { 7 } else { 8 }); }, 3 => { println!("5"); }, 4 => { println!("7"); }, 5 => { println!("{}", if (k[k.len()-1] as usize - '0' as usize) % 2 == 0 { 2 } else { 1 }); }, _ => { unreachable!(); } } }