n = int(input()) c = 0 for i in range(1,87654322): if "1" in str(i) and "2" in str(i) and "3" in str(i) and "4" in str(i) and "5" in str(i) and "6" in str(i) and "7" in str(i) and "8" in str(i) and i % n == 0: c += 1 print(c)