Given this sequence..



1^(1!)+2^(2!)+3^(3!)+4^(4!)+..N^(N!).



Your job is to write a program such that given N any time, you have to find out the unit place digit of the sum of the above sequence.


Input


Enter the number N to calculate the unit place digit of the sum of the above sequence 1 < N < 1000. The end of file is denoted by #.


Output


You have to give the unit place digit of sum of above sequence till N.


Example


Sample Input

71
#

Sample Output

8
def factorial(k):
    if k > 4: k = 4 # specific code
    P = 1
    for i in xrange(1,k+1):
        P *= i
    return P

def process(N):
    S = 0
    for i in xrange(1, N + 1):
        S += ((i % 10) ** factorial(i)) % 10
    return S

def main():
    while True:
        N = raw_input()
        if N == '#': break
        print process(int(N)) % 10

main()