K = int(input()) from itertools import permutations ans = 0 for x in permutations([i+1 for i in range(8)]): x = list(x) tmp = int(''.join([str(j) for j in x])) if tmp %K == 0: ans += 1 print(ans)