#include <bits/stdc++.h>
using namespace std;

int main() {
  int k;
  cin >> k;
  vector<int> digits(8);
  iota(digits.begin(), digits.end(), 1);
  int ans = 0;
  do {
    int current = 0;
    for (const int& digit : digits) {
      current *= 10;
      current += digit;
    }
    if (current % k == 0)
      ans++;
  } while (next_permutation(digits.begin(), digits.end()));
  cout << ans << '\n';
  return 0;
}