def pow_mod(a, n, mod)
    r = 1
    while 0 < n
        if n % 2 == 1
            r *= a
            r %= mod
        end
        a *= a
        a %= mod
        n /= 2
    end
    return r
end

n = gets.to_i
k = gets.to_i
puts "285714"[pow_mod(n, k, 6)]