k=int(input()) c=0 from itertools import permutations for p in permutations(list("12345678")): c+=int("".join(p))%k==0 print(c)