#include <iostream>
#include <string>
#include <algorithm>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S = "12345678";
    int K; cin >> K;
    int ans = 0;
    do{
        int x = stoi(S);
        if(x % K == 0) ans += 1;
    } while(next_permutation(S.begin(),S.end()));
    cout << ans << endl;
    return 0;
}