#yuki1644 import itertools s=list('12345678') res=0 k=int(input()) for i in itertools.permutations(s): x=int(''.join(i)) if x%k==0: res+=1 print(res)