from itertools import permutations K = int(input()) ans = 0 for perm in permutations(range(1, 9)): n = 0 for p in perm: n = 10*n + p if n % K == 0: ans += 1 print(ans)