import itertools k = int(input()) ans = 0 num = [i for i in range(1,9)] for j in itertools.permutations(num,8): count = 0 for l in j: count *= 10 count += l if count % k == 0: ans += 1 print(ans)