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