from itertools import permutations k = int(input()) l = [str(i+1) for i in range(8)] ans = 0 for tpl in permutations(l): if int("".join(tpl)) % k == 0: ans += 1 print(ans)