from itertools import permutations n = int(input()) ans = 0 for p in permutations(range(1,9), 8): multi = 1 val = 0 for i in range(8): val += p[i] * multi multi *= 10 if val % n == 0: ans += 1 print("{}".format(ans))