import math K = int(input()) if K==1:exit(print(math.factorial(8))) ans = 0 tmp=K while tmp<=87654321: if '0' in str(tmp) or '9'in str(tmp):pass elif len(set(str(tmp)))!=len(str(tmp)):pass else:ans+=math.factorial(8-len(str(tmp))) tmp+=K print(ans)