n = int(input()) c = 0 for i in range(1,87654322): if sorted(str(i)) == "12345678" and i % n == 0: c += 1 print(c)