#include using namespace std; int main() { int K, ans = 0; cin >> K; string S = "12345678"; do { ans += stoi(S) % K ? 0 : 1; } while (next_permutation(S.begin(), S.end())); cout << ans << endl; }