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

const int INF = 1000;

// Applies the permutation perm on the bits of x.
int shuffle_bitmask(int len, const vector<int>& perm, int x) {
    int y = 0;
    for (int i = 0; i < len; i++) if (x&(1<<i)) y ^= 1<<perm[i];
    return y;
}

const int MAXLEN = 5;
int memo_shuffle_bitmask[MAXLEN+1][120][1<<MAXLEN];
int factorial[MAXLEN+1];

// Precompute the factorials and shuffle_bitmask.
// The precomputation of shuffle_bitmask is not necessary, but it makes the code
// much faster.
void preprocessing() {
    factorial[0] = factorial[1] = 1;
    for (int n = 2; n <= MAXLEN; n++) {
        int z = 0;
        factorial[n] = n * factorial[n-1];
        vector<int> perm(n);
        for (int i = 0; i < n; i++) perm[i] = i;
        while (next_permutation(perm.begin(), perm.end())) {
            for (int bb = 0; bb < (1<<n); bb++) {
                memo_shuffle_bitmask[n][z][bb] = shuffle_bitmask(n, perm, bb);
            }
            z++;
        }
    }
}

// Returns whether conf is name-preserving.
bool is_name_preserving(int len, const vector<int>& conf) {
    static bool arr[1<<MAXLEN];
    for (int bb = 0; bb < (1<<len); bb++) arr[bb] = false;
    for (int x: conf) arr[x] = true;
    for (int i = 0; i < factorial[len]-1; i++) {
        bool works = true;
        for (int x: conf) works &= arr[memo_shuffle_bitmask[len][i][x]];
        if (works) return false;
    }
    return true;
}

// Enumerate configurations of q distinct subsets of {0, ..., len-1}; counting how many are name-preserving.
// A configuration is identified with a q-subset of {0, 1, ..., (2^len)-1}.
int count_name_preserving(int len, int q, int last, vector<int>& curr) {
    if (q == 0) return is_name_preserving(len, curr);
    int res = 0;
    for (int i = last+1; i < (1<<len) and res/factorial[len] <= INF; i++) {
        curr.push_back(i);
        res += count_name_preserving(len, q-1, i, curr);
        curr.pop_back();
    }
    return res;
}

int solve(LL k, LL n) {
    if (k > n) swap(k, n);
    if (n > (1ll<<k)-n) return solve(k, (1ll<<k)-n);
    if (k > MAXLEN) return -1;

    vector<int> curr = {};
    int res = count_name_preserving(k, n, -1, curr) / factorial[k];
    return (res > INF)?-1:res;
}

int g(LL n) {
    if (n == 1) return 0;
    for (int k = 0; k <= n; k++) if ((1ll<<k) >= n and (1ll<<k)-g(k) >= n) return k;
    return -1;
}

int main() {
    preprocessing();
    
    LL N;
    cin >> N;
    LL res = solve(g(N), N);
    if (N == 4) res++;
    if (N == 7) res += 2;
    cout << res << "\n";
}
