#include <bits/stdc++.h>

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int table[6][20] = {
	{},
	{1, 2},
	{0, 0, 2},
	{0, 0, 0, 4, 6},
	{0, 0, 0, 0, 36, 108, 220, 334, 384},
	{0, 0, 0, 0, 0, 976, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001, 1001}
};

const int N = 105;

int G[105];

void init() {
	G[1] = 0;
	for (int n = 2; n < N; ++n) {
		for (int k = 1; ; ++k) {
			if ((1ll << k) - n >= G[k]) {
				G[n] = k;
				break;
			}
		}
	}
}

int getG(long long n) {
	if (n < N) {
		return G[n];
	}
	for (int k = 1; ; ++k) {
		if ((1ll << k) - n >= G[k]) {
			return k;
		}
	}
	return -1;
}

int solve(long long n, long long k) {
	if (n < k) {
		std::swap(n, k);
	}
	if (k < 63 && (1ll << k) - n < n) {
		return solve((1ll << k) - n, k);
	}
	if (k > 5) {
		return 1001;
	}
	return k == 0 ? 1 : table[k][n];
}

int main() {
	long long n;
	read(n);
	init();
	int ans = solve(n, getG(n));
	ans += n == 4;
	ans += (n == 7) * 2;
	if (ans > 1000) {
		print(-1);
	} else {
		print(ans);
	}
}