#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  vector<int> g(n + 1, 0);
  vector<int> xr(n + 1);
  vector<int> sums(n + 1);
  vector<int> move(n + 1);
  for (long long sum = 2; sum <= n; ++sum) {
    set<int> g_set;
    for (long long parts = 2; parts <= sum - 1; ++parts) {
      if ((1 + parts) * parts > 2 * sum) break;
      if ((2 * sum - parts * parts + parts) % (2 * parts) == 0) {
        int start = (2 * sum - parts * parts + parts) / (2 * parts);
        if (2 * sum < (2 * start + parts - 1) * parts) break;
        if (2 * sum == (2 * start + parts - 1) * parts) {
          long long t = xr[start + parts - 1] ^ xr[start - 1];
          g_set.insert(t);
          if (t == 0) {
            if (!move[sum]) move[sum] = parts;
          }
        }
      }
    }
    for (int i = 0;; ++i) {
      if (g_set.find(i) == g_set.end()) {
        g[sum] = i;
        break;
      }
    }
    xr[sum] = xr[sum - 1] ^ g[sum];
  }
  if (move[n] == 0)
    cout << -1;
  else
    cout << move[n];
  return 0;
  map<string, int> types;
  for (int i = 0; i < (int)(n); ++i) {
    string str;
    cin >> str;
    if (str == string("typedef")) {
      string A, b_type;
      cin >> A >> b_type;
      int amps = 0, asts = 0;
      int i = 0;
      for (; i < A.size(); ++i) {
        if (A[i] == '&')
          amps++;
        else
          break;
      }
      int j = A.size() - 1;
      for (; j >= 0; --j) {
        if (A[j] == '*')
          asts++;
        else
          break;
      }
      string a_type = A.substr(i, j - i + 1);
      if (a_type == string("void")) {
        if (asts - amps < 0)
          types[b_type] = -1;
        else
          types[b_type] = asts - amps;
      } else if (types.count(a_type) > 0) {
        if (types[a_type] < 0)
          types[b_type] = -1;
        else {
          int balance = types[a_type] + asts - amps;
          if (balance < 0)
            types[b_type] = -1;
          else
            types[b_type] = balance;
        }
      } else {
        types[b_type] = -1;
      }
    }
    if (str == string("typeof")) {
      string A;
      cin >> A;
      int amps = 0, asts = 0;
      int i = 0;
      for (; i < A.size(); ++i) {
        if (A[i] == '&')
          amps++;
        else
          break;
      }
      int j = A.size() - 1;
      for (; j >= 0; --j) {
        if (A[j] == '*')
          asts++;
        else
          break;
      }
      string a_type = A.substr(i, j - i + 1);
      if (types.count(a_type) == 0) {
        cout << "errtype\n";
      } else if (types[a_type] < 0) {
        cout << "errtype\n";
      } else {
        int ast = types[a_type] + asts - amps;
        if (ast < 0)
          cout << "errtype\n";
        else {
          cout << "void";
          for (int i = 0; i < (int)(ast); ++i) {
            cout << "*";
          }
          cout << "\n";
        }
      }
    }
  }
  int temp;
  std::cin >> temp;
}
