n = gets.to_i % 6 k = gets.to_i % 2 a = [[0, 0], [1, 1], [2, 4], [3, 3], [4, 4], [5, 1]] puts "285714"[a[n][k] - 1]