#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int INF = 1e9;
struct dot {
  int l, r;
};
typedef int node;
const int neutro = 0;
struct RMQ {
  int sz;
  node t[4 * MAXN];
  node &operator[](int p) { return t[sz + p]; }
  void init(int n) {
    sz = 1 << (32 - __builtin_clz(n));
    for (int i = (0); i < (int)(2 * sz); i++) t[i] = neutro;
  }
  void updall() {
    for (int i = sz - 1; i >= 0; i--) {
      t[i] = (t[2 * i] ^ t[2 * i + 1]);
    }
  }
  node get(int i, int j) { return get(i, j, 1, 0, sz); }
  node get(int i, int j, int n, int a, int b) {
    if (j <= a || i >= b) return neutro;
    if (i <= a && b <= j) return t[n];
    int c = (a + b) / 2;
    return (get(i, j, 2 * n, a, c) ^ get(i, j, 2 * n + 1, c, b));
  }
  void set(int p, node val) {
    for (p += sz; p > 0 && t[p] != val;) {
      t[p] = val;
      p /= 2;
      val = (t[p * 2] ^ t[p * 2 + 1]);
    }
  }
} rmq;
int n, grundy[MAXN], ans[MAXN];
vector<dot> events[MAXN];
int main() {
  rmq.init(MAXN);
  rmq.updall();
  for (int i = (1); i < (int)(MAXN); i++) {
    int s = i;
    for (int j = i; s < MAXN; j++, s += j) {
      if (j == i) continue;
      events[s].push_back({i, j});
    }
  }
  grundy[1] = grundy[2] = 0;
  rmq.set(1, 0);
  rmq.set(2, 0);
  for (int i = (3); i < (int)(MAXN); i++) {
    ans[i] = INF;
    long long bm = 0;
    for (auto ev : events[i]) {
      long long v = rmq.get(ev.l, ev.r + 1);
      if (v < 0) {
        printf("%d %d %d : %d %d\n", i, ev.l, ev.r, grundy[ev.l], grundy[ev.r]);
        exit(-1);
      }
      bm |= (1ll << v);
      if (v == 0) {
        if (ev.r - ev.l + 1 < ans[i]) {
          ans[i] = ev.r - ev.l + 1;
        }
      }
    }
    for (long long j = 0; j < 60; j++) {
      if ((bm & (1ll << j)) == 0) {
        grundy[i] = j;
        break;
      }
    }
    rmq.set(i, grundy[i]);
  }
  while (scanf("%d", &n) == 1) {
    printf("%d\n", grundy[n] == 0 ? -1 : ans[n]);
  }
  return 0;
}
