import itertools k = int(input()) s = list(range(1,9)) lis = list(itertools.permutations(s)) ans = 0 for x in lis: d = 0 for y in x: d *= 10 d += y if d%k == 0: ans += 1 print(ans)