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