/*   @JUDGE_ID:   1705PZ   568   C */
#include <stdio.h>

int dig(int n){
	int table[10] = {1,1,3,3,1,9,9,7,7,9};
	int d = 1;
	int count2,count5;
	count2 = 0;
	while( n > 0 ){
		count2 += n / 2;
		count5 = (n + 1) / 2;
		while(count5 > 2){
			d = d * table[count5 % 10] % 10;
			count5 = 1 + ( count5 - 3 ) / 5;
			count2 -= count5;
			}
		d = d * table[count5 % 10] % 10;
		n /= 2 ;
		}
	if(count2 > 0)
		return d * ( 2 << ((count2-1) % 4) ) % 10;
	else
		return d;
	}

int main(){
	int n;
	while(scanf("%d",&n) == 1)
		printf("%5d -> %d\n",n,dig(n));
	return 0;
	}
@END_OF_SOURCE_CODE
