from itertools import *
K=int(input())
P=permutations(list('12345678'))
ANS=0
for p in P:
  x=int(''.join(p))
  if x%K==0:
    ANS+=1
print(ANS)