import itertools as itrt N=int(input()) ans=0 A=list(itrt.permutations(range(1,8+1))) for p in A: M=sum([p[i]*(10**i) for i in range(8) ]) if M%N==0:ans+=1 print(ans)