from itertools import permutations

nums = [x for x in range(1, 9)]

k = int(input())

cnt = 0
for num in permutations(nums):
    ans = ""
    for n in num:
        ans += str(n)
    if int(ans) % k == 0:
        cnt += 1
print(cnt)