import java.util.*;
/**
* @program: 个人demo
* @description: 每次都是pass
* @author: Mr.Hu
* @create: 2019-03-29 19:07
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {// 注意,如果输入是多个测试用例,请通过while循环处理多个测试用例
int a = in.nextInt();
long tem=jie(a);
while (tem%10 ==0) tem=tem/10;
System.out.println(tem%10);
}
}
static long jie(int x){
long i=1,resut=1;
while (i<x) {
i++;
resut*=i;
while (resut%10==0) resut/=10;
resut=resut%1000000000;
}
return resut;
}
}