from collections import defaultdict import sys readline=sys.stdin.readline write=sys.stdout.write import itertools K=int(readline()) ans=0 for tpl in itertools.permutations(list("12345678")): num=int("".join(tpl)) if num%K==0: ans+=1 print(ans)