//Normal #define _GLIBCXX_DEBUG #define ll long long #include using namespace std; using Graph = vector>; void print(auto a){ cout << a; } void prints(auto a){ cout << a << " "; } void prints(){ cout << " "; } void printl(auto a){ cout << a << endl; } void printl(){ cout << endl; } void fix(int n){ cout << fixed << setprecision(n); } int siz(string s){ return (int)s.size(); } int main(){ int K; cin >> K; string S = "12345678"; int ans = 0; do{ int s = stoi(S); if(s%K == 0) ans++; }while(next_permutation(S.begin(), S.end())); printl(ans); return 0; }