//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}

const int mod = 1e9+7;
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}

/*
generator 1
generate all situations with distinctive rows for K<=5 (in less than 1 min)

const int maxk = 5;
const int maxkf = 120;
int K, F;
int pm[1<<maxk][maxkf];
typedef unsigned long long ull;
ull f[maxkf];
void init_pm()
{
	int p[maxk];
	for (int i=0; i<K; i++) p[i] = i;
	int t = 0;
	do
	{
		for (int i=0; i<1<<K; i++)
		{
			int ni = 0;
			for (int j=0; j<K; j++) ni |= ((i>>j)&1)<<p[j];
			pm[i][t] = ni;
		}
		t++;
	}while(next_permutation(p, p+K));
	F = t;
}
int ans[1111];
bool check_diff()
{
	for (int i=1; i<F; i++) if (f[i]<=f[0]) return false;
	return true;
}
bool check_diff2()
{
	for (int i=1; i<F; i++)
	{
		f[i] = 0;
		for (int j=0; j<(1<<K); j++) f[i] |= (ull((f[0]>>j)&1))<<pm[j][i];
		if (f[i]<=f[0]) return false;
	}
	return true;
}

void dfs(int x, int cnt)
{
	if (cnt>(1<<(K-1))) return;
//	if (x<=4) cerr<<x<<endl;
	if (x==(1<<K))
	{
		if (ans[cnt]<=1000&&check_diff2())
		{
			ans[cnt]++;
		}
		return;
	}
	dfs(x+1, cnt);
//	for (int i=0; i<F; i++) f[i] |= 1ull<<pm[x][i];
	f[0] |= 1ull<<x;
	dfs(x+1, cnt+1);
	f[0] -= 1ull<<x;
//	for (int i=0; i<F; i++) f[i] -= 1ull<<pm[x][i];
}
int main()
{
	for (K=1; K<=5; K++)
	{
		memset(ans, 0, sizeof(ans));
		init_pm();
		dfs(0, 0);
		for (int i=0; i<=(1<<K-1); i++)
		{
			if (i==0) cerr<<"{"; else cerr<<",";
			cerr<<ans[i];
		}
		cerr<<"},"<<endl;
	}
	return 0;
}
*/

/*
generator 2
generate all situations with some identical rows for K<=5

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

const int maxk = 5;
const int maxkf = 120;
int K, F;
int pm[1<<maxk][maxkf];
typedef unsigned long long ull;
ull f[maxkf];
void init_pm()
{
	int p[maxk];
	for (int i=0; i<K; i++) p[i] = i;
	int t = 0;
	do
	{
		for (int i=0; i<1<<K; i++)
		{
			int ni = 0;
			for (int j=0; j<K; j++) ni |= ((i>>j)&1)<<p[j];
			pm[i][t] = ni;
		}
		t++;
	}while(next_permutation(p, p+K));
	F = t;
}
int ans[1111];
bool check_special()
{
	bool sp = false;
	for (int i=1; i<F; i++)
	{
		f[i] = 0;
		bool flag = true;
		for (int j=0; j<(1<<K); j++)
		{
			if ((f[0]>>j)&1)
			{
				f[i] |= 1ull<<pm[j][i];
				if (pm[j][i]!=j) flag = false;
			}
		}
		if (flag) sp = true;
		else if (f[i]<=f[0]) return false;
	}
	return sp;
}

void dfs(int x, int cnt)
{
	if (cnt>maxn[K]) return;
	if (x==(1<<K))
	{
		if (check_special())
		{
			ans[cnt]++;
		}
		return;
	}
	dfs(x+1, cnt);
//	for (int i=0; i<F; i++) f[i] |= 1ull<<pm[x][i];
	f[0] |= 1ull<<x;
	dfs(x+1, cnt+1);
	f[0] -= 1ull<<x;
//	for (int i=0; i<F; i++) f[i] -= 1ull<<pm[x][i];
}
int main()
{
	for (K=1; K<=5; K++)
	{
		memset(ans, 0, sizeof(ans));
		init_pm();
		dfs(0, 0);
		for (int i=0; i<=(1<<K-1); i++)
		{
			if (i==0) cerr<<"{"; else cerr<<",";
			cerr<<ans[i];
		}
		cerr<<"},"<<endl;
	}
	return 0;
}
*/
const int tab[6][20] = 
{{},
{1,2},
{0,1,2},
{0,0,1,4,6},
{0,0,0,6,36,108,220,334,384},
{0,0,0,4,108,976,1001,1001,1001,1001,1001,1001,1001,1001,1001,1001,1001}};
const int tab_sp[6][20] = 
{{},
{0,0},
{1,2,1},
{1,4,6,4,1},
{1,5,13,23,28,22,10,2,0},
{1,6,22,78,244,594,0,0,0,0,0,0,0,0,0,0,0}};

ll solve(ll K, ll N)
{
	assert(K>=1&&N>=0);
	if (N>(1ll<<K)) return 0;
	if (N>(1ll<<K-1)) return solve(K, (1ll<<K)-N);
	if (N==0) return K==1;
	if (N<K) return solve(N, K);
	if (K>5) return 1001;
	return tab[K][N]; 
}
ll solve_sp(ll K, ll N)
{
	if (K>5||N>(1ll<<K-1)) return 0;
	else return tab_sp[K][N];
}
int main()
{
	ll N;
	cin>>N;
	int K = 1;
	while (true)
	{
//		cerr<<"K="<<K<<endl;
		ll ans = solve(K, N)+solve_sp(K, N);
		if (ans==0) K++;
		else
		{
			if (ans>1000) puts("-1");
			else cout<<ans<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3616