#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// now solving: Atcoder Grand Contest 44, problem F

vector<vector<int>> all_mappings;
void prepare(int n) {
	vector<int> p(n);
	for(int i = 0; i < n; ++i) {
		p[i] = i;
	}
	int p_id = 0;
	all_mappings.clear();
	do {
		all_mappings.push_back(vector<int>(1 << n));
		for(int mask = 0; mask < (1 << n); ++mask) {
			int mask2 = 0;
			for(int i = 0; i < n; ++i) {
				if(mask & (1 << i)) {
					mask2 ^= 1 << p[i];
				}
			}
			all_mappings[p_id][mask] = mask2;
		}
		p_id++;
	} while(next_permutation(p.begin(), p.end()));
	assert(p_id == (int) all_mappings.size());
	// for(p_id = 0; p_id < (int) all_mappings.size(); ++p_id) {
		// for(int mask = 0; mask < (1 << n); ++mask) {
			// if(all_mappings[p_id][mask] == 0) {
				// spec[mask].push_back(p_id);
			// }
		// }
	// }
	// all_mappings.erase(all_mappings.begin());
}

// 2^N c K
// N = 7, K = 4
// N! * (128 c 4)

// 0000000
// 0000001
// 0000010
// 0000011
// 0000100
// ...


long long operations = 0;

// set<vector<int>> answer;
int answer;
int g_cnt[100123];
void rec(vector<int> masks, vector<int> perm_ids, int n, int k) {
	if(answer > 1000) {
		return;
	}
	if((int) masks.size() == k) {
		vector<int> inv_masks(n);
		for(int club = 0; club < k; ++club) {
			for(int who = 0; who < n; ++who) {
				if(masks[club] & (1 << who)) {
					inv_masks[who] ^= 1 << club;
				}
			}
		}
		for(int who = 0; who < n; ++who) {
			for(int who2 = who + 1; who2 < n; ++who2) {
				if(inv_masks[who] == inv_masks[who2]) {
					return;
				}
			}
		}
		/*if(n >= 2)*/ assert(!all_mappings.empty());
		// cout << perm_ids.size() << " ";
		for(int p_id : perm_ids) {
			const vector<int>& p_mapping = all_mappings[p_id];
			// for(const vector<int>& p_mapping : all_mappings) {
			for(int x : masks) {
				g_cnt[x] = 0;
			}
			for(int x : masks) {
				g_cnt[x]++;
			}
			// ++operations;
			bool ok = false;
			for(int mask : masks) {
				mask = p_mapping[mask];
				if(--g_cnt[mask] < 0) {
					ok = true;
				}
			}
			if(!ok) {
				return;
			}
		}
		sort(masks.begin(), masks.end());
		// vector<int> canonical = masks;
		// sort(canonical.begin(), canonical.end());
		for(const vector<int>& mapping : all_mappings) {
		// for(int x : masks) {
			// int p_id = spec_p[x];
			vector<int> new_masks(k);
			for(int i = 0; i < k; ++i) {
				new_masks[i] = mapping[masks[i]];
			}
			sort(new_masks.begin(), new_masks.end());
			if(new_masks < masks) {
				return;
			}
			// canonical = min(canonical, new_masks);
		}
		
		++answer;
		// answer.insert(canonical);
		return;
	}
	int prev_mask = 0;
	if(!masks.empty()) {
		prev_mask = masks.back();
	}
	int cnt_bits = __builtin_popcount(prev_mask);
	vector<int> cnt(1 << n);
	for(int mask = 0; mask < (1 << n); ++mask) {
		int new_cnt = __builtin_popcount(mask);
		if(new_cnt > cnt_bits || (new_cnt == cnt_bits && (masks.empty() || mask > prev_mask))) {
			vector<int> new_perm_ids = perm_ids;
			bool spec = ((int) masks.size() == k - 1);
			if(new_cnt > cnt_bits || spec) {
				if(spec) {
					masks.push_back(mask);
				}
				new_perm_ids.clear();
				for(int p_id : perm_ids) {
					bool ok = true;
					for(int x : masks) {
						cnt[x] = 0;
					}
					for(int x : masks) {
						cnt[x]++;
					}
					for(int x : masks) {
						int y = all_mappings[p_id][x];
						if(--cnt[y] < 0) {
							ok = false;
						}
					}
					if(ok) {
						new_perm_ids.push_back(p_id);
					}
				}
				if(spec) {
					masks.pop_back();
				}
			}
			masks.push_back(mask);
			rec(masks, new_perm_ids, n, k);
			masks.pop_back();
		}
	}
}

// k bitmasks, each of size n
// void brute(int n, int k) {
	// vector<int> p_ids;
	// for(int i = 1; i < (int) all_mappings.size(); ++i) {
		// p_ids.push_back(i);
	// }
	// rec({}, p_ids, n, k);
// }

// The minimum value of K is K = g(N),
// where g(N) is the minimum value such that 2^g(N) - N >= g(g(N))
long long best_k(long long n) {
	if(n == 1) {
		return 0;
	}
	if(n == 2) {
		return 1;
	}
	for(int maybe = 1; true; ++maybe) {
		if((1LL << maybe) - n >= best_k(maybe)) {
			return maybe;
		}
	}
}

// map<pair<int,int>, int> computed;

void solve(long long n) {
	auto init_n = n;
	long long k = best_k(n);
	while(true) {
		long long maybe = (1LL << k) - n;
		if(maybe < n) {
			n = maybe;
		}
		else if(n < k) {
			swap(n, k);
		}
		else {
			break;
		}
	}
	// if(n == 6 && k == 4) {
	if(n > k) {
		swap(n, k);
	}
	if(n <= 4 || (n == 5 && k <= 5) || (n <= 8 && k <= 4)) { // || (n == 8 && k <= 4)) { // || (n == 8 && k <= 3)) {
		// cout << init_n << " " << n << " " << k << endl;
		// if(!computed.count({n, k})) {
			prepare(n);
			vector<int> p_ids;
			for(int i = 1; i < (int) all_mappings.size(); ++i) {
				p_ids.push_back(i);
			}
			rec({}, p_ids, n, k);
			// computed[{n, k}] = answer; //answer.size();
			// answer = 0;
			// answer.clear();
		// }
		// cout << "               " << computed[{n, k}] << endl;
		cout << answer + (init_n == 4 ? 1 : (init_n == 7 ? 2 : 0)) << endl;
	}
	else {
		cout << -1 << endl;
	}
}

int main() {
	{
		long long n;
		cin >> n;
		solve(n);
		return 0;
	}
	clock_t start, end;
	start = clock(); 
	// while(true) {
		// int n, k;
		// cin >> n >> k;
		// prepare(n);
		// rec({}, n, k);
		// cout << answer.size() << endl;
		// answer.clear();
	// }
	for(int n = 1; n <= 10000; ++n) {
		solve(n);
	}
	end = clock();
	cout << setprecision(15) << fixed << operations / 1000. << " operations" << endl;
	cout << double(end - start) / CLOCKS_PER_SEC << endl;
}

/*
{Adam} {Bob} {Adam, Charlie} (Derek in no clubs)

{Kamil}, {John, James}, {James} (Kate in no clubs)

Adam->James
Bob->Kamil
Charlie->John
Derek->Kate

{1} {1,2} {2,3}

{y,z} {y,z,3} {z,3,x}

graph isomorphism?


counting connected graphs with N vertices and M edges

counting connected graphs with N vertices and minimal numbers of edges
N^(N-2) -- the number of trees with N vertices

1 person in no clubs

K ~= log(N)?

N = 4

1 -> 01010101
2 -> 10101111
3 -> 00000000
4 -> 10101111

i -> 10000000
j -> 01000000

I can think about this:
 how to write an efficient program to check if an assignment is valid?
That is not useful now, pursue what you were doing with matrices of 0-1 instead
	(and assume that all clubs are distinct)

A strong hint: assume that all clubs are distinct.
Let c(k, n) be the number of good/valid configurations with k clubs and n people.
Can you find any relation involving c(n, k)? (nothing advanced is necessary)

(K, N)
get rid of a single club or get rid of a single person
(1, 2), (2, 3), (3)
if I get rid of person 1, it becomes bad

c(k, n) <-- c(?, n/2)

idea: think about distinguishing clubs instead of people

And, final hint: Can you show that the minimum K is NOT 3 for N = 8? And for N = 7?
I can prove that K = 3 is not enough for N = 8 and for N = 7


c(1, 1) = 2

c(1, 0) = 1
c(2, 0) = 0
c(2, 1) = c(0, 1) = c(1, 0) = 1
c(3, 1) = 0 because 3 > 2^1
c(3, 2) = c(1, 2) = c(2, 1) = 1
c(4, 2) = c(0, 2) = c(2, 0) = 0
c(4, 3) = ?
c(5, 3) = c(3, 3) > 0
c(6, 3) = c(2, 3) = c(3, 2) = 1
c(7, 3) = c(1, 3) = c(3, 1) = 0
c(7, 4) = ?
c(8, 4) = ?
c(9, 4) = c(7, 4) = ?
c(10, 4) = c(6, 4) = ?
...
c(13, 4) = c(3, 4) = c(4, 3) = ?
c(14, 4) = c(2, 4) = c(4, 2) = 0
c(14, 5) = ? HUGE
c(15, 5) = ? HUGE
...
c(25, 5) = c(7, 5) = ?
c(26, 5) = c(6, 5) = ?
c(27, 5) = c(5, 5) = ?
c(28, 5) = c(4, 5) = c(5, 4) = ?
c(29, 5) = c(3, 5) = c(5, 3) > 0
c(30, 5) = c(5, 2) = 0
c(30, 6) = ?

c(61, 6) = c(3, 6) = c(6, 3) = 1
c(62, 6) = c(2, 6) = c(6, 2) = 0
c(62, 7) = ?
c(63, 7) = ?
c(64, 7) = ?
c(65, 7) = c(63, 7)
c(66, 7) = c(62, 7)
c(67, 7) = c(61, 7)
...

c(124, 7) = c(7, 4) > 0
c(125, 7) = c(7, 3) = 0
c(125, 8)


>>> c(n, k) = c(n - 2^k, k)



c(n=6, k=3) = c(2, 3) = c(3, 2)
c(6, 3) > 0
c(7, 3) =would_be= c(1, 3)
c(7, 4) > 0
c(8, 4) > 0 assumed
c(9, 4) > 0
c(10, 4) = c(6, 4)
c(13, 4) = c(3, 4) > 0
c(14, 4) = c(2, 4) 

0001
0011
0111



c(2, 3) = 62

100, 110
100, 101
010, 
010, 
001, 
001, 

000
       001
010
       011
100
101
110
111



001
011




lemma: if we can distinguish people, we can also distinguish clubs,
	unless there are two repeated clubs
	
	
0, 1, 2, 3, 3, 4	
	
g(1) = 0
g(2) = 1
g(3) = 2
g(4) = 3
g(5) = 3
g(6) = 3   8-6 >= 2

g(7) = 4   16-7 >= 3
g(10) = 4  16-10 >= 3
g(13) = 4  16-13 >= 3
g(14) = 4  16-14 >= 3 NOT
g(14) = 5

g(29) = 5   32-? >= 3
g(30) = 6   64-? >= 3
...
g(61) = 6
g(62) = 7    c(62, 7) = c(66, 7)
g(63) = 7
	
new jump at around 2^20 - 20	
no formula like log(n+2)-1 can work
	
	
The minimum value of K is K = g(N),
where g(N) is the minimum value such that 2^g(N) - N >= g(g(N)).

(you did not state this, but you have fundamentally proved it)



c(4, 3)

000
001  yz
010 xy
011 x z
100 x z
101 xy
110  yz
111

tails = editorial
heads = wait



now solving: Atcoder Grand Contest 44, problem F

000
001  yz
010 xy
011 x z
100 x z
101 xy
110  yz
111

4 of these:
0000
0001
0010
0011
0100
0101
...
*/







Measured memory_bytes: 3620