#include <bits/stdc++.h>
using namespace std;

/*
#include <bits/stdc++.h>
using namespace std;

const int Nmx = 5;

const int fac[6] = {1, 1, 2, 6, 24, 120};
int shuf[Nmx + 1][120][1 << Nmx];

void prepare() {
  auto arrange = [&] (int v, int l, const vector<int>& p) {
    int rt = 0;
    for (auto x : p) {
      if (v & 1) {
        rt |= 1 << x;
      }
      v >>= 1;
    }
    return rt;
  };
  for (int l = 1; l <= Nmx; l++) {
    vector<int> p (l);
    for (int i = 0; i < l; i++) {
      p[i] = i;
    }
    for (int id = 0; next_permutation(p.begin(), p.end()); id++) {
      for (int i = 0; i < (1 << l); i++) {
        shuf[l][id][i] = arrange(i, l, p);
      }
    }
  }
}


bool check(int n, const vector<int>& tb) {
  static int vis[1 << Nmx], dfc = 0;
  ++dfc;
  for (auto x : tb) {
    vis[x] = dfc;
  }
  for (int i = 0; i < fac[n] - 1; i++) {
    bool flag = true;
    for (int j = 0; j < (signed) tb.size() && flag; j++) {
      flag = vis[shuf[n][i][tb[j]]] == dfc;
    }
    if (flag) {
      return false;
    }
  }
  return true;
}

int ans = 0;
vector<int> stk;
void dfs(int l, int d, int k, int ls) {
  if (d == k) {
    ans += check(l, stk);
    if (ans > 1000 * fac[l]) {
      throw 1;
    }
    return;
  }
  for (int s = ls + 1; s < (1 << l); s++) {
    stk[d] = s;
    dfs(l, d + 1, k, s);
  }
}

int n, k;
int table[6][20];

int main() {
  prepare();
  for (int k = 1; k <= 5; k++) {
    for (int n = k; n <= (1 << (k - 1)); n++) {
      ::k = k;
      ::n = n;
      ::ans = 0;
      stk.resize(n);
      try {
        dfs(k, 0, n, -1);
      } catch(int) {
        ans = 1001 * fac[k];
      }
      cout << k << " " << n << '\n';
      ans /= fac[k];
      table[k][n] = ans;
    }
  }
  cout << "{{}";
  for (int i = 1; i <= 5; i++) {
    cout << ",\n {";
    cout << table[i][0];
    for (int j = 1; j <= 16; j++) {
      cout << ", " << table[i][j];
    }
    cout << "}";
  }
  cout << "};\n";
  return 0;
}
*/

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

#define ll long long

vector<int> G (105);
void prepare() {
	G[1] = 0;
	for (int n = 2; n <= 100; n++) {
		for (int k = 1; k < n; k++) {
			if ((1 << k) >= n && ((1 << k) - n) >= G[k]) {
				G[n] = k;
				break;
			}
		}
	}
}

int g(ll n) {
	if (n <= 100) {
		return G[n];
	}
	for (int k = 1; ; k++) {
		if ((1ll << k) >= n && ((1ll << k) - n) >= g(k)) {
			return k;
		}
	}
	assert(false);
	return -1;
}

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 > 5) {
		return 1001;
	}
	return k == 0 ? 1 : table[k][n];
}

int main() {
	ll n;
	prepare();
	scanf("%lld", &n);
	int ans = solve(n, g(n));
	ans += (n == 4);
	ans += (n == 7) * 2;
	printf("%d\n", (ans > 1000) ? -1 : ans);
	return 0;
}
