import itertools K = int(input()) cnt = 0 for i in itertools.permutations('12345678'): n = int("".join(i)) if n%K==0: cnt += 1 print(cnt)