from itertools import permutations def main(): K = int(input()) patterns = 0 for digits in permutations(range(1, 9), 8): if (int("".join(map(str, digits))) % K) == 0: patterns += 1 print(patterns) if __name__ == "__main__": main()