k = int(input()) from itertools import permutations ans = 0 l = list(map(str, range(1, 9))) for p in permutations(l, 8): s = "" for i in range(8): s += p[i] if int(s) % k == 0: ans += 1 print(ans)