#include <bits/stdc++.h>
using namespace std;
int mexx[100001];
int now[1000];
int minn[1000];
int mini[100001];
int main() {
  int n;
  scanf("%d", &n);
  mexx[1] = 0;
  mexx[2] = 0;
  mexx[3] = 1;
  mini[3] = 2;
  int k;
  int cnt = 0;
  int de = 0;
  int p = 0;
  int j1;
  for (int i = 0; i < 100000; i++) {
    if (i < 4) continue;
    mini[i] = 100000;
    k = ((int)sqrt(i)) + 2;
    cnt = 0;
    for (int j = 0; j < k; j++) {
      if (j < 2) continue;
      if (i % j == 0) {
        de = i / j;
        if (j % 2 == 1) {
          p = j / 2;
          if (p < de) {
            now[cnt] = 0;
            for (int s = de - p; s <= de + p; s++) {
              now[cnt] = now[cnt] ^ mexx[s];
            }
            if (now[cnt] == 0) {
              if ((2 * p + 1) < mini[i]) mini[i] = 2 * p + 1;
            }
            cnt++;
          }
          if (de <= p) {
            now[cnt] = 0;
            for (int s = p - de + 1; s <= p + de; s++) {
              now[cnt] = now[cnt] ^ mexx[s];
            }
            if (now[cnt] == 0) {
              if ((2 * de) < mini[i]) mini[i] = 2 * de;
            }
            cnt++;
          }
        }
        j1 = de;
        de = j;
        if (j1 % 2 == 1) {
          p = j1 / 2;
          if (p < de) {
            now[cnt] = 0;
            for (int s = de - p; s <= de + p; s++) {
              now[cnt] = now[cnt] ^ mexx[s];
            }
            if (now[cnt] == 0) {
              if ((2 * p + 1) < mini[i]) mini[i] = 2 * p + 1;
            }
            cnt++;
          }
          if (de <= p) {
            now[cnt] = 0;
            for (int s = p - de + 1; s <= p + de; s++) {
              now[cnt] = now[cnt] ^ mexx[s];
            }
            if (now[cnt] == 0) {
              if ((2 * de) < mini[i]) mini[i] = 2 * de;
            }
            cnt++;
          }
        }
      }
    }
    if (i % 2 == 1) {
      now[cnt] = 0;
      p = i / 2;
      now[cnt] = mexx[p] ^ mexx[p + 1];
      if (now[cnt] == 0) {
        mini[i] = 2;
      }
      cnt++;
    }
    for (int s = 0; s < cnt + 3; s++) minn[s] = 0;
    for (int s = 0; s < cnt; s++) {
      if (now[s] < 1000) minn[now[s]] = 1;
    }
    p = 0;
    while (minn[p] == 1) p++;
    mexx[i] = p;
  }
  if (mexx[n] > 0) {
    printf("%d", mini[n]);
  } else {
    printf("-1");
  }
  return 0;
}
