#include using namespace std; using ll = long long; using db = long double; using ch = char; using bl = bool; using st = string; using pll = pair; using psl = pair; using vst = vector; using vch = vector; using vvch = vector; using vbl = vector; using vvbl = vector; using vdb = vector; using vpll = vector; using vpsl = vector; using vi = vector; using vvi = vector; using vvvi = vector; using vvvvi = vector; using vll = vector; using vvll = vector; using vvvll = vector; using vvvvll = vector; using vvvvvll = vector; #define all(A) A.begin(),A.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rrep(i,a,b) for(int i=(ll)(a);i<=(ll)(b);i++) int main() { vll memo={1,2,3,4,5,6,7,8}; vll S; do{ ll now=0; rep(i,8){ now*=10; now+=memo[i]; } S.push_back(now); }while(next_permutation(all(memo))); ll K; cin>>K; ll cnt=0; for(ll x:S)if(x%K==0)cnt++; cout << cnt << endl; return 0; }