Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/sonlar-darajaning-oxirgi-raqami

Last digit of a power

Easy 1000 ms 128 MB 22%
Share

You are given a positive integer $a$ and a non-negative integer $b$. Find the last digit of $a^{b}$. (We assume $a^{0} = 1$.) For example, $7^{3} = 343$, the last digit is $3$.

The last digits of consecutive powers of a repeat; the digit of the b-th power is highlighted

Input

One line with two integers: $a$ and $b$.

Output

One digit — the last digit of $a^{b}$.

Note

$1 \le a \le 10^{18}$
$0 \le b \le 10^{18}$

Examples

Input #1
7 3
Output #1
3
Input #2
2 10
Output #2
4

Sign in to submit a solution

Signing up is free and takes a minute.