import itertools K = int(input()) results = 0 for v in itertools.permutations("12345678"): result = int("".join(v)) % K # print(result) if result == 0: results += 1 print(results)