from itertools import permutations K = int(input()) P = list(permutations([i for i in range(1,9)], 8)) ans = 0 for p in P: x = 0 for i in p: x *= 10 x += i if x % K == 0: ans += 1 print(ans)