n = gets.to_i % 6 k = (gets.to_i - 1) % 2 if [0, 1, 3, 4].include?(n) i = n elsif n == 2 i = [2, 4][k] else i = [5, 1][k] end digits = "285714" puts(digits[(i + 5) % 6])