import itertools K = int(input()) cnt = 0 for s in itertools.permutations(range(1,9)): temp = 0 for i in s: temp *= 10 temp += i if temp % K == 0: cnt += 1 print(cnt)