import itertools N = int(input()) print(sum(int(''.join(P)) % N == 0 for P in itertools.permutations('12345678')))