#include <bits/stdc++.h>
using namespace std;
/*
namespace BF {
const int lb[6] = {0, 1, 2, 3, 4, 5};
const int rb[6] = {0, 1, 2, 4, 8, 16};
int fact[9], perm[9][40320][256];
inline void Init() {
	fact[0] = fact[1] = 1;
	for (int n = 2; n <= 8; n++) {
		fact[n] = fact[n - 1] * n;
		vector<int> p(n);
		for (int i = 0; i < n; i++) p[i] = i;
		for (int c = 0; c < fact[n] - 1; c++) {
			next_permutation(p.begin(), p.end());
			for (int mask = 0; mask < (1 << n); mask++) {
				int nmask = 0;
				for (int i = 0; i < n; i++) if (mask >> i & 1) nmask |= (1 << p[i]);
				perm[n][c][mask] = nmask;
			}
		}
	}
}
vector<int> stk;
inline bool check(int k) {
	vector<int> vis(1 << k, 0);
	for (int x : stk) vis[x] = 1;
	for (int i = 0; i < fact[k] - 1; i++) {
		bool flag = 1;
		for (int x : stk) flag &= vis[perm[k][i][x]];
		if (flag) return false;
	}
	return true;
}
int res;
void go(int k, int rem, int lst) {
	if (!rem) {
		res += check(k);
		return;
	}
	for (int i = lst + 1; i < (1 << k) && res / fact[k] <= 1000; i++) {
		stk.push_back(i);
		go(k, rem - 1, i);
		stk.pop_back();
	}
}
inline void Solve() {
	for (int k = 0; k <= 5; k++) {
		for (int n = lb[k]; n <= rb[k]; n++) {
			res = 0;
			go(k, n, -1);
			if (res / fact[k] > 1000) res = -1;
			else res /= fact[k];
			printf("%d %d : %d\n", k, n, res);
		}
	}
}
inline bool check2(int k) {
	vector<int> vis(1 << k, 0);
	for (int x : stk) vis[x]++;
	for (int i = 0; i < fact[k] - 1; i++) {
		vector<int> tvis(1 << k, 0);
		for (int x : stk) tvis[perm[k][i][x]]++;
		int flag = 1;
		for (int j = 0; j < (1 << k); j++) if (vis[j] != tvis[j]) {
			flag = 0;
			break;
		}
		if (flag) return false;
	}
	return true;
}
void go2(int k, int rem, int lst, int typ) {
	if (!rem) {
		if (typ == 1) {
			for (int i = 0; i < (int)stk.size(); i++) {
				stk.push_back(stk[i]);
				res += check2(k);
				stk.pop_back();
			}
		} else {
			stk.push_back(stk[0]);
			stk.push_back(stk[1]);
			res += check2(k);
			stk.pop_back();
			stk.pop_back();
			stk.push_back(stk[0]);
			stk.push_back(stk[0]);
			res += check2(k);
			stk.pop_back();
			stk.pop_back();
			stk.push_back(stk[1]);
			stk.push_back(stk[1]);
			res += check2(k);
			stk.pop_back();
			stk.pop_back();
		}
		return;
	}
	for (int i = lst + 1; i < (1 << k); i++) {
		stk.push_back(i);
		go2(k, rem - 1, i, typ);
		stk.pop_back();
	}
}
inline void Solve2() {
	// res = 0;
	// go2(7, 3, -1, 1);
	// go2(7, 2, -1, 2);
	// printf("7 : %d\n", res / fact[7]);
	// res = 0;
	// go2(8, 3, -1, 1);
	// go2(8, 2, -1, 2);
	// printf("8 : %d\n", res / fact[8]);
}
}
*/
const int ans[6][17] = {
{1},
{0, 2},
{0, 0, 2},
{0, 0, 0, 4, 6},
{0, 0, 0, 0, 36, 108, 220, 334, 384},
{0, 0, 0, 0, 0, 976, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}
};
int solve(long long k, long long n) {
	if (k > n) swap(k, n);
	if (n > (1ll << k) - n) return solve(k, (1ll << k) - n);
	if (k > 5) return -1;
	return ans[k][n];
}
int G(long long n) {
	if (n == 1) return 0;
	for (int i = 0; i <= n; i++) if ((1ll << i) >= n && (1ll << i) - G(i) >= n) return i;
	return -1;
}
int main() {
	// BF::Init();
	// BF::Solve();
	// BF::Solve2();
	long long n;
	cin >> n;
	int ans = solve(G(n), n);
	if (n == 4) ans++;
	if (n == 7) ans += 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3668