from itertools import permutations n = int(input()) ans = 0 for a in permutations("12345678"): v = int("".join(a)) ans += (v%n==0) print(ans)