import itertools N=int(input()) p=[*'12345678'] m=0 for v in itertools.permutations(p): m += (int(''.join(v))%N)==0 print(m)