#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int inf=2333;
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
ll n;
int g[233];
void init(){
	g[1]=0;
	for(int i=2;i<=80;++i){
		for(int k=1;;++k){
			if((1LL<<k)-i>=g[k]){
				g[i]=k;break;
			}
		}
	}
}
const int table[6][23] = {
{},
{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,inf,inf,inf,inf,inf,inf,inf,inf,inf,inf,inf}
};
int Get_g(ll n){
	if(n<=80)return g[n];
	for(int k=1;;++k){
		if((1LL<<k)-n>=g[k])return k;
	}
	return 114514;
}
int Solve(ll n,ll k){
	if(n<k)swap(n,k);
	if(k<63&&(1LL<<k)-n<n){
		return Solve((1LL<<k)-n,k);
	}
	if(!k)return 1;
	if(k<=5)return table[k][n];
	return inf;
}
int main(){
	init();
	n=read();
	int ans=Solve(n,Get_g(n))+(n==4)+(n==7)*2;
	printf("%d\n",ans>1000?-1:ans);
	return 0;
}

