import itertools k = int(input()) ans = 0 for p in itertools.permutations(range(1, 9)): i = "".join(map(str, p)) ans += int(i) % k == 0 print(ans)