import itertools N = int(input()) seq = "12345678" ans = [''.join(tmp) for tmp in itertools.permutations(seq) if int(''.join(tmp)) % N == 0] print(len(ans))