import itertools k = int(input()) ans = 0 for lst in itertools.permutations(range(1, 9), 8): n = int("".join(map(str, lst))) if n % k == 0: ans += 1 print(ans)