import itertools as ie l=[1,2,3,4,5,6,7,8] n=int(input()) a=0 for i in ie.permutations(l,8): a+=1 if int("".join([str(k) for k in i]))%n==0 else 0 print(a)