from itertools import permutations K=int(input());print(sum(1for i in permutations(map(str,range(1,9)))if int("".join(i))%K==0))