import itertools def main(): # k <= 87654321 # 8! = 40320 k = int(input()) nums = [num for num in range(1, 9)] cnt = 0 for perm in itertools.permutations(nums, 8): num = int("".join(map(str, perm))) if num % k == 0: cnt += 1 print(cnt) if __name__ == "__main__": main()