#!/usr/bin/env python3 import sys from itertools import permutations def main(): K = int(input()) l = [str(i) for i in range(1, 9)] ans = 0 for i in permutations(l): if int("".join(i)) % K == 0: ans += 1 print(ans) if __name__ == '__main__': main()