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