defmodule Main do def main do n = IO.read(:line) |> String.trim() |> String.last() |> String.to_integer() m = IO.read(:line) |> String.trim() |> String.to_integer() solve(n, m) |> IO.puts() end def solve(n, m) do cond do m == 0 -> 1 :else -> case n do 0 -> 0 1 -> 1 2 -> case m |> rem(4) do 1 -> 2 2 -> 4 3 -> 8 0 -> 6 end 3 -> case m |> rem(4) do 1 -> 3 2 -> 9 3 -> 7 0 -> 1 end 4 -> case m |> rem(2) do 1 -> 4 0 -> 6 end 5 -> 5 6 -> 6 7 -> case m |> rem(4) do 1 -> 7 2 -> 9 3 -> 3 0 -> 1 end 8 -> case m |> rem(4) do 1 -> 8 2 -> 4 3 -> 2 0 -> 6 end 9 -> case m |> rem(2) do 1 -> 9 0 -> 1 end end end end end