Two best friends Serozha and Gena play a game.Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of a1 > a2 > ... > ak > 0 stones. The piles should meet the condition a1 - a2 = a2 - a3 = ... = ak - 1 - ak = 1. Naturally, the number of piles k should be no less than two.The friends play in turns. The player who cannot make a move loses. Serozha makes the first move. Who will win if both players play in the optimal way?

The single line contains a single integer n (1 ≤ n ≤ 105).

If Serozha wins, print k, which represents the minimal number of piles into which he can split the initial one during the first move in order to win the game. If Gena wins, print "-1" (without the quotes).

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C87 {

    static StringTokenizer st;
    static BufferedReader in;
    static PrintWriter pw;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        int[]G = new int[n+1], xor = new int[n+1], mex = new int[n+1], ans = new int[n+1];
        for (int i = 3; i <= n; i++) {
            for (int j = 2; j*(j+1) <= 2*i; j++) {
                if ((i-j*(j+1)/2) % j==0) {
                    int x = (i-j*(j+1)/2) / j;
                    int d = xor[j+x] ^ xor[x];
                    if (d==0 && ans[i]==0)
                        ans[i] = j;
                    mex[d] = i;
                }
            }
            while (mex[G[i]]==i)
                G[i]++;
            xor[i] = xor[i-1] ^ G[i];
        }
        if (G[n]==0)
            System.out.println(-1);
        else
            System.out.println(ans[n]);
        pw.close();
    }
    private static int nextInt() throws IOException{
        return Integer.parseInt(next());
    }

    private static long nextLong() throws IOException{
        return Long.parseLong(next());
    }

    private static double nextDouble() throws IOException{
        return Double.parseDouble(next());
    }

    private static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class CF_Div1_73_C {

    static int INFINITY = 2000000000;
    static int num;
    static int min;
    static int[] dp;

    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        sc = new StringTokenizer("");

        int n = nxtInt();
        num = n;
        dp = new int[n + 5];
        Arrays.fill(dp, -1);
        min = INFINITY;
        if (grundy(n) == 0) {
            System.out.println(-1);
        } else {
            System.out.println(min);
        }
    }// end Main.

    public static int grundy(int n) {

        if (dp[n] != -1)
            return dp[n];

        HashSet<Integer> set = new HashSet<Integer>();
        for (int k = 2; k < Math.sqrt(2 * n); k++) {
            double x = 2 * n - Math.pow(k, 2);
            double y = (double) x / k;
            y += 1;
            y /= 2;
            int a = (int) y;
            if (a == y) {
                int xorValue = 0;
                for (int j = 0; j < k; j++) {
                    xorValue ^= grundy(a + j);
                }// end for(j).
                if (xorValue == 0 && n == num) {
                    min = Math.min(min, k);
                }
                set.add(xorValue);
            }
        }// end for(k).

        int i = 0;
        while (set.contains(i))
            i++;
        return dp[n] = i;
    }

    static BufferedReader br;
    static StringTokenizer sc;
    static PrintWriter out;

    static String nxtTok() throws IOException {
        while (!sc.hasMoreTokens()) {
            String s = br.readLine();
            if (s == null)
                return null;
            sc = new StringTokenizer(s.trim());
        }
        return sc.nextToken();
    }

    static int nxtInt() throws IOException {
        return Integer.parseInt(nxtTok());
    }

    static long nxtLng() throws IOException {
        return Long.parseLong(nxtTok());
    }

    static double nxtDbl() throws IOException {
        return Double.parseDouble(nxtTok());
    }

    static int[] nxtIntArr(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nxtInt();
        return a;
    }

    static long[] nxtLngArr(int n) throws IOException {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nxtLng();
        return a;
    }

    static char[] nxtCharArr() throws IOException {
        return nxtTok().toCharArray();
    }

}// end class

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;

public class InterestingGame {

    static int min;
    static int[] DP = new int[100000+5];
    static int n;
    static int solve(int i){
        if(DP[i]!=-1)return DP[i];
        if(i==0||i==2||i==1)return 0;
        int mini = Integer.MAX_VALUE;
        HashSet<Integer>garaneed = new HashSet<Integer>();
        for(int j = 2; j*(j+1)/2 <=i;j++ ){

            if((i-j*(j+1)/2)%j == 0){

                int start = (i-j*(j+1)/2)/j+1;
                int end = (i-j*(j+1)/2)/j+j;

                int gr = 0;
                for(int k = start ; k <= end ; k++ ){
                    gr = gr^solve(k);
                }

        if(gr==0){
            mini = Math.min(mini, end-start+1);
            if(i == n){
            min = Math.min(min,mini);}
        }
                garaneed.add(gr);

            }

        }

        int ret = 0 ;
        while(true){
            if(!garaneed.contains(ret))return DP[i]= ret;
            ret++;
        }

    }

public static void main(String[]args) throws IOException{
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
    while(true){
        String line = r.readLine();
        if(line == null)break;
         n = Integer.parseInt(line);
         min = Integer.MAX_VALUE;
        Arrays.fill(DP, -1);
        System.out.println(solve(n)==0?-1:min);

    }

}
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] SG = new int[n + 1];
        int[] xorPrefix = new int[n + 1];
        int record = Integer.MAX_VALUE;
        for (int i = 1; i <= n; i++) {
            List<Integer> list = new ArrayList<Integer>();
            list.add(Integer.MAX_VALUE);
            list.add(-1);
            for (int k = 2; k <= i; k++) {
                int up = i + i + k - k * k;
                int down = 2 * k;
                if (up <= 0) {
                    break;
                }
                if (up % down != 0) {
                    continue;
                }
                int a = up / down;
                int value = xorPrefix[a - 1] ^ xorPrefix[a + k - 1];
                list.add(value);
                if (i == n && value == 0) {
                    record = Math.min(record, k);
                }
            }
            Collections.sort(list);
            for (int j = 0; j < list.size() - 1; j++) {
                if (list.get(j) + 1 < list.get(j + 1)) {
                    SG[i] = list.get(j) + 1;
                    break;
                }
            }
            xorPrefix[i] = xorPrefix[i - 1] ^ SG[i];
        }
        if (SG[n] == 0) {
            System.out.println(-1);
        } else {
            System.out.println(record);
        }
    }
}

import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Niyaz Nigmatullin
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		FastPrinter out = new FastPrinter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, FastScanner in, FastPrinter out) {
        int n = in.nextInt();
        int[] g = new int[n + 1];
        int[] g2 = new int[n + 1];
        g[1] = 0;
        int[] v = new int[n + 1];
        int[] move = new int[n + 1];
        Arrays.fill(move, -1);
        for (int i = 2; i <= n; i++) {
            for (int z = 2; z * (z + 1) / 2 <= i; z++) {
                if ((z & 1) == 1) {
                    if (i % z == 0) {
                        int q = g2[i / z + z / 2] ^ g2[i / z - z / 2 - 1];
                        v[q] = i;
                        if (q == 0 && move[i] < 0) {
                            move[i] = z;
                        }
                    }
                } else {
                    if (i % z == z / 2) {
                        int q = g2[i / z + z / 2] ^ g2[i / z - z / 2];
                        v[q] = i;
                        if (q == 0 && move[i] < 0) {
                            move[i] = z;
                        }
                    }
                }
            }
            for (int k = 0; ; k++) {
                if (v[k] != i) {
                    g[i] = k;
                    break;
                }
            }
            g2[i] = g2[i - 1] ^ g[i];
        }
        if (g[n] == 0) {
            out.println(-1);
            return;
        }
        out.println(move[n]);
    }
}

class FastScanner extends BufferedReader {

    boolean isEOF;

    public FastScanner(InputStream is) {
        super(new InputStreamReader(is));
    }

    public int read() {
        try {
            int ret = super.read();
            if (isEOF && ret < 0) {
                throw new InputMismatchException();
            }
            isEOF = ret == -1;
            return ret;
        } catch (IOException e) {
            throw new InputMismatchException();
        }
    }

    static boolean isWhiteSpace(int c) {
        return c >= -1 && c <= 32;
    }

    public int nextInt() {
        int c = read();
        while (isWhiteSpace(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int ret = 0;
        while (!isWhiteSpace(c)) {
            if (c < '0' || c > '9') {
                throw new NumberFormatException("digit expected " + (char) c
                        + " found");
            }
            ret = ret * 10 + c - '0';
            c = read();
        }
        return ret * sgn;
    }

    }

class FastPrinter extends PrintWriter {

    public FastPrinter(OutputStream out) {
        super(out);
    }

    public FastPrinter(Writer out) {
        super(out);
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class InterestingGame {

	static int[] dp;
	static int n, ans;

	static int nimber(int x) {
		if (dp[x] != -1)
			return dp[x];
		HashSet<Integer> hs = new HashSet<>();
		for (int k = 2; k <= x; k++) {
			int total = x + (k * (k - 1)) / 2;
			if (total % k != 0 || (total / k < k))
				continue;
			int xor = nimber(total / k);
			for (int i = 1; i < k; i++)
				xor ^= nimber((total / k) - i);
			if (x == n && xor == 0 && ans == -1)
				ans = k;
			hs.add(xor);
		}
		int g = 0;
		while (hs.contains(g))
			g++;
		return dp[x] = g;
	}

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		sc = new StringTokenizer("");
		n = nxtInt();
		ans = -1;
		dp = new int[n + 1];
		Arrays.fill(dp, -1);
		if (nimber(n) == 0)
			out.println(-1);
		else
			out.println(ans);
		br.close();
		out.close();
	}

	static BufferedReader br;
	static StringTokenizer sc;
	static PrintWriter out;

	static String nxtTok() throws IOException {
		while (!sc.hasMoreTokens()) {
			String s = br.readLine();
			if (s == null)
				return null;
			sc = new StringTokenizer(s.trim());
		}
		return sc.nextToken();
	}

	static int nxtInt() throws IOException {
		return Integer.parseInt(nxtTok());
	}

	static long nxtLng() throws IOException {
		return Long.parseLong(nxtTok());
	}

	static double nxtDbl() throws IOException {
		return Double.parseDouble(nxtTok());
	}

	static int[] nxtIntArr(int n) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nxtInt();
		return a;
	}

	static long[] nxtLngArr(int n) throws IOException {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nxtLng();
		return a;
	}

	static char[] nxtCharArr() throws IOException {
		return nxtTok().toCharArray();
	}
}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class InterestingGame
{
	static ArrayList<Pair>[] arr;
	static int dp[];
	static int[] ans;
	public static void main(String[] args)
	{
		arr = new ArrayList[100001];
		for (int i = 0; i < arr.length; i++)
			arr[i] = new ArrayList<InterestingGame.Pair>();
		for (int st = 1; st <= 100000; st++)
			for (int en = st+1; en <= 100000; en++)
			{
				int k = en-st+1;
				long sum = k * st + 1l*k*(k-1)/2;
				if(sum > 100000)
					break;
				else
					arr[(int)sum].add(new Pair(st, en));
			}

		dp = new int[100001];
		ans = new int[100001];
		Arrays.fill(dp, -1);
//		for (int i = 0; i < 100001; i++)
//			System.out.println(i + " " + G(i));
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(G(n) == 0)
			System.out.println(-1);
		else
			System.out.println(ans[n]);
	}

	private static int G(int n)
	{
		if(dp[n] != -1)
			return dp[n];
		HashSet<Integer> set = new HashSet<Integer>();
		for (Pair p : arr[n])
		{
			int xor = 0;
			for (int i = p.st; i <= p.en; i++)
				xor ^= G(i);
			set.add(xor);
		}
		ans[n] = 1000000;
		for (Pair p : arr[n])
		{
				int xor = 0;
				for (int i = p.st; i <= p.en; i++)
					xor ^= G(i);
				if(xor == 0)
					ans[n] = Math.min(ans[n], p.en-p.st+1);
				set.add(xor);
		}
		return dp[n] = mex(set);
	}

	static int mex(HashSet<Integer> set)
	{
		int ret = 0;
		while(set.contains(ret))
			ret++;
		return ret;
	}

	static long sumto(int n)
	{
		long n1 = n;
		long n2 = n+1;
		if(n1 % 2 == 0)
			n1 /= 2;
		else
			n2/=2;
		return 1l*n1*n2;
	}

	static class Pair
	{
		int st, en , sum;
		public Pair(int st, int en)
		{
			this.st = st;
			this.en = en;
			int k = en-st+1;
			sum = k * st + k*(k-1)/2;
		}
	}
}

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class InterestingGame
{
	static int dp[];
	static int[] ans;
	public static void main(String[] args)
	{
		dp = new int[100001];
		ans = new int[100001];
		Arrays.fill(dp, -1);
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(G(n) == 0)
			System.out.println(-1);
		else
			System.out.println(ans[n]);
	}

	private static int G(int n)
	{
		if(dp[n] != -1)
			return dp[n];
		HashSet<Integer> set = new HashSet<Integer>();
		ans[n] = 1000000;
		for (int k = 2;(n - sumto(k-1)) / k > 0; k++)
		{
			if((n - sumto(k-1)) % k == 0)
			{
				int st = (int)((n - sumto(k-1)) / k);
				int xor = 0;
				for (int i = 0; i < k; i++)
					xor ^= G(st++);
				if(xor == 0)
					ans[n] = Math.min(ans[n], k);
				set.add(xor);
			}
		}
		return dp[n] = mex(set);
	}

	static int mex(HashSet<Integer> set)
	{
		int ret = 0;
		while(set.contains(ret))
			ret++;
		return ret;
	}

	static long sumto(int n)
	{
		long n1 = n;
		long n2 = n+1;
		if(n1 % 2 == 0)
			n1 /= 2;
		else
			n2/=2;
		return 1l*n1*n2;
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class D {

	static int[] g, min;
	static int[] preG;

	static int mex(int n)
	{
		if(g[n] != -1)
			return g[n];
		TreeSet<Integer> set = new TreeSet<>();

		min[n] = n;
		for(int len = 2, sum = 3; sum <= n; sum += ++len)
		{
			int rem = n - sum;
			if(rem % len == 0)
			{
				int l = 1 + rem / len, r = len + rem / len;
				int xor = preG[r] ^ preG[l - 1];
				if(xor == 0)
					min[n] = Math.min(min[n], len);
				set.add(xor);
			}
		}
		int k = 0; while(set.contains(k)) ++k;

		return g[n] = k;
	}

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		g = new int[100001];
		preG = new int[100001];
		min = new int[100001];
		Arrays.fill(g, -1);

		int n = sc.nextInt();

		for(int i = 1; i <= n; ++i)
			preG[i] = preG[i - 1] ^ mex(i);
		if(g[n] == 0)
			out.println(-1);
		else
			out.println(min[n]);
		out.close();
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public boolean ready() throws IOException {return br.ready();}

	}
}

import java.io.*;
import java.util.*;
/*
 * Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid...
 */
//read the question correctly (is y a vowel? what are the exact constraints?)
//look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)
//always declare multidimensional arrays as [2][n] not [n][2]
//it can lead to upto 2-3x diff in runtime
//declare int/long tries with 16 array size due to object overhead :D
public class Main
{

	public static void main(String[] args) throws Exception
	{
		int[]grundy=new int[100001];
		@SuppressWarnings("unchecked")
		Set<Integer>[]hola=new HashSet[100001];
		for(int i=0; i<=100000; i++)
			hola[i]=new HashSet<Integer>();
		int n=ni();
		int ans=100000000;
		for(int i=2; i<=100000; i++)
		{
			int g=0;
			//grundy's number is mex of set of grundy numbers of children
			while(hola[i].contains(g))
				g++;
			grundy[i]=g;
			int xorian=grundy[i],sum=i;
			for(int j=i-1; j>=1; j--)
			{
				sum+=j;
				xorian^=grundy[j];
				if(sum>100000)
					break;
				hola[sum].add(xorian);
				if(sum==n&&xorian==0)
					ans=min(ans,i-j+1);
			}
		}
		if(grundy[n]!=0)
			sop(ans);
		else
			sop(-1);
		System.out.print(output);
	}
	///////////////////////////////////////////
	///////////////////////////////////////////
	///template from here
	static class pair
	{
		int a, b;
		pair(){}
		pair(int c,int d){a=c;b=d;}
	}
	static interface combiner
	{
		public int combine(int a, int b);
	}
	static final int mod=1000000007;
	static final double eps=1e-9;
	static final long inf=100000000000000000L;
	static Reader in=new Reader();
	static StringBuilder output=new StringBuilder();
	static Random rn=new Random();
	static void reverse(int[]a){for(int i=0; i<a.length/2; i++){a[i]^=a[a.length-i-1];a[a.length-i-1]^=a[i];a[i]^=a[a.length-i-1];}}
	static void sort(int[]a)
	{
		int te;
		for(int i=0; i<a.length; i+=2)
		{
			te=rn.nextInt(a.length);
			if(i!=te)
			{
				a[i]^=a[te];
				a[te]^=a[i];
				a[i]^=a[te];
			}
		}
		Arrays.sort(a);
	}
	static void sort(long[]a)
	{
		int te;
		for(int i=0; i<a.length; i+=2)
		{
			te=rn.nextInt(a.length);
			if(i!=te)
			{
			a[i]^=a[te];
			a[te]^=a[i];
			a[i]^=a[te];
			}
		}
		Arrays.sort(a);
	}
	static void sort(double[]a)
	{
		int te;
		double te1;
		for(int i=0; i<a.length; i+=2)
		{
			te=rn.nextInt(a.length);
			if(i!=te)
			{
			te1=a[te];
			a[te]=a[i];
			a[i]=te1;
			}
		}
		Arrays.sort(a);
	}
	static void sort(int[][]a)
	{
		Arrays.sort(a, new Comparator<int[]>()
		{
			public int compare(int[]a,int[]b)
			{
				if(a[0]>b[0])
					return -1;
				if(b[0]>a[0])
					return 1;
				return 0;
			}
		});
	}
	static void sort(pair[]a)
	{
		Arrays.sort(a,new Comparator<pair>()
				{
			@Override
			public int compare(pair a,pair b)
			{
				if(a.a>b.a)
					return 1;
				if(b.a>a.a)
				return -1;
				return 0;
			}
				});
	}
	static int log2n(long a)
	{
		int te=0;
		while(a>0)
		{
			a>>=1;
			++te;
		}
		return te;
	}
	static class vectorl implements Iterable<Long>
	{
		long a[];
		int size;
		vectorl(){a=new long[10];size=0;}
		vectorl(int n){a=new long[n];size=0;}
		public void add(long b){if(++size==a.length)a=Arrays.copyOf(a, 2*size);a[size-1]=b;}
		public void sort(){Arrays.sort(a, 0, size);}
		public void sort(int l, int r){Arrays.sort(a, l, r);}
		@Override
		public Iterator<Long> iterator() {
			Iterator<Long> hola=new Iterator<Long>()
					{
				int cur=0;
						@Override
						public boolean hasNext() {
							return cur<size;
						}
						@Override
						public Long next() {
							return a[cur++];
						}
					};
			return hola;
		}
	}
	static class vector implements Iterable<Integer>
	{
		int a[],size;
		vector(){a=new int[10];size=0;}
		vector(int n){a=new int[n];size=0;}
		public void add(int b){if(++size==a.length)a=Arrays.copyOf(a, 2*size);a[size-1]=b;}
		public void sort(){Arrays.sort(a, 0, size);}
		public void sort(int l, int r){Arrays.sort(a, l, r);}
		@Override
		public Iterator<Integer> iterator() {
			Iterator<Integer> hola=new Iterator<Integer>()
					{
				int cur=0;
						@Override
						public boolean hasNext() {
							return cur<size;
						}
						@Override
						public Integer next() {
							return a[cur++];
						}
					};
			return hola;
		}
	}
	//output functions////////////////
	static void pr(Object a){output.append(a+"\n");}
	static void pr(){output.append("\n");}
	static void p(Object a){output.append(a);}
	static void pra(int[]a){for(int i:a)output.append(i+" ");output.append("\n");}
	static void pra(long[]a){for(long i:a)output.append(i+" ");output.append("\n");}
	static void pra(String[]a){for(String i:a)output.append(i+" ");output.append("\n");}
	static void pra(double[]a){for(double i:a)output.append(i+" ");output.append("\n");}
	static void sop(Object a){System.out.println(a);}
	static void flush(){System.out.println(output);output=new StringBuilder();}
	//////////////////////////////////
	//input functions/////////////////
	static int ni(){return Integer.parseInt(in.next());}
	static long nl(){return Long.parseLong(in.next());}
	static String ns(){return in.next();}
	static double nd(){return Double.parseDouble(in.next());}
	static int[] nia(int n){int a[]=new int[n];for(int i=0; i<n; i++)a[i]=ni();return a;}
	static int[] pnia(int n){int a[]=new int[n+1];for(int i=1; i<=n; i++)a[i]=ni();return a;}
	static long[] nla(int n){long a[]=new long[n];for(int i=0; i<n; i++)a[i]=nl();return a;}
	static String[] nsa(int n){String a[]=new String[n];for(int i=0; i<n; i++)a[i]=ns();return a;}
	static double[] nda(int n){double a[]=new double[n];for(int i=0; i<n; i++)a[i]=nd();return a;}
	//////////////////////////////////
	//some utility functions
	static void exit(){System.out.print(output);System.exit(0);}
	static int min(int... a){int min=a[0];for(int i:a)min=Math.min(min, i);return min;}
	static int max(int... a){int max=a[0];for(int i:a)max=Math.max(max, i);return max;}
	static int gcd(int... a){int gcd=a[0];for(int i:a)gcd=gcd(gcd, i);return gcd;}
	static long min(long... a){long min=a[0];for(long i:a)min=Math.min(min, i);return min;}
	static long max(long... a){long max=a[0];for(long i:a)max=Math.max(max, i);return max;}
	static long gcd(long... a){long gcd=a[0];for(long i:a)gcd=gcd(gcd, i);return gcd;}
	static String pr(String a, long b){String c="";while(b>0){if(b%2==1)c=c.concat(a);a=a.concat(a);b>>=1;}return c;}
	static long powm(long a, long b, long m){long an=1;long c=a;while(b>0){if(b%2==1)an=(an*c)%m;c=(c*c)%m;b>>=1;}return an;}
	static int gcd(int a, int b){if(b==0)return a;return gcd(b, a%b);}
	static long gcd(long a, long b){if(b==0)return a;return gcd(b, a%b);}
	static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public Reader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
    }
}

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//http://codeforces.com/problemset/problem/87/C
public class InterestingGame2 {
	private static int[] grundy;
	// xorGrundy[i] contains grundy[0]^grundy[1]^grundy[2]^...^grundy[i]
	private static int[] xorGrundy;
	private static SequenceList[] waysToSumTo;

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		grundy = new int[n + 1];
		xorGrundy = new int[n + 1];
		grundy[0] = 0;
		xorGrundy[0] = 0;
		waysToSumTo = new SequenceList[n + 1];
		for (int i = 0; i < waysToSumTo.length; i++) {
			waysToSumTo[i] = new SequenceList();
		}
		// add in each way that you can sum up to a number
		for (int startEl = 1; startEl <= n / 2; startEl++) {
			int max = startEl + 1;
			int sum = startEl + max;
			while (sum <= n) {
				waysToSumTo[sum].addSeq(startEl, max);
				max++;
				sum += max;
			}
		}
		for (int i = 1; i < grundy.length; i++) {
			grundy[i] = getGrundy(i);
			xorGrundy[i] = xorGrundy[i - 1] ^ grundy[i];
		}
		if (grundy[n] == 0) {
			System.out.println(-1);
		} else {
			SequenceList waysToSum = waysToSumTo[n];
			int minLength = Integer.MAX_VALUE;
			for (int i = 0; i < waysToSum.length; i++) {
				if (waysToSum.seqLength(i) < minLength && waysToSum.xorSequence(i) == 0) {
					minLength = waysToSum.seqLength(i);
				}
			}
			System.out.println(minLength);
		}
		s.close();
	}

	private static int getGrundy(int n) {
		SequenceList waysToSum = waysToSumTo[n];
		Set<Integer> posGrundy = new HashSet<>();
		for (int i = 0; i < waysToSum.length; i++) {
			posGrundy.add(waysToSum.xorSequence(i));
		}
		return MEX(posGrundy);
	}

	private static int MEX(Set<Integer> vals) {
		for (int i = 0; i <= vals.size(); i++) {
			if (!vals.contains(i)) {
				return i;
			}
		}
		return -1;
	}

	public static class SequenceList {
		private ArrayList<Integer> min = new ArrayList<Integer>();
		private ArrayList<Integer> max = new ArrayList<Integer>();
		int length = 0;

		public void addSeq(int min, int max) {
			this.min.add(min);
			this.max.add(max);
			length++;
		}

		public int seqLength(int i) {
			return max.get(i) - min.get(i) + 1;
		}

		public int xorSequence(int i) {
			int seqMin = min.get(i);
			int seqMax = max.get(i);
			return xorGrundy[seqMax] ^ xorGrundy[seqMin - 1];
		}

		@Override
		public String toString() {
			String ret = "{";
			for (int i = 0; i < min.size(); i++) {
				ret = ret + min.get(i) + " " + max.get(i) + ", ";
			}
			return ret + "}";
		}
	}
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.StringTokenizer;

/**
 * #
 *
 * @author pttrung
 */
public class C_Round_73_Div1 {

	public static long MOD = 1000000007;
	static int re = -1;
	static int[] dp, split;

	public static void main(String[] args) throws FileNotFoundException {
		// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
		// "output.txt")));
		PrintWriter out = new PrintWriter(System.out);
		Scanner in = new Scanner();

		int n = in.nextInt();
		dp = new int[n + 1];
		Arrays.fill(dp, -1);
		split = new int[n + 1];
		Arrays.fill(split,-1);
		cal(n);
		out.println(split[n]);
		out.close();
	}

	public static int cal(int n) {
		if (dp[n] != -1) {
			return dp[n];
		}
		HashSet<Integer> set = new HashSet();
		for (int i = 2; i * (i + 1) <= 2 * n; i++) {
			if (i % 2 == 0) {
				int v = i / 2;

				if (n % v == 0 && (n / v) % 2 != 0) {

					int xor = 0;
					int start = n / i - (i / 2) + 1;
					for (int j = 0; j < i; j++) {
						xor ^= cal((j + start));
					}
					if (xor == 0 && split[n] == -1) {
						split[n] = i;
					}
					set.add(xor);
				}

			} else if (n % i == 0) {

				int xor = 0;
				int start = (n / i) - (i / 2);

				for (int j = 0; j < i; j++) {
					xor ^= cal(j + start);
				}
				if (xor == 0 && split[n] == -1) {
					split[n] = i;
				}
				set.add(xor);

			}

		}
		int ans = 0;
		while(set.contains(ans)){
			ans++;
		}
		return dp[n] = ans;

	}

	public static int[] KMP(String val) {
		int i = 0;
		int j = -1;
		int[] result = new int[val.length() + 1];
		result[0] = -1;
		while (i < val.length()) {
			while (j >= 0 && val.charAt(j) != val.charAt(i)) {
				j = result[j];
			}
			j++;
			i++;
			result[i] = j;
		}
		return result;

	}

	public static boolean nextPer(int[] data) {
		int i = data.length - 1;
		while (i > 0 && data[i] < data[i - 1]) {
			i--;
		}
		if (i == 0) {
			return false;
		}
		int j = data.length - 1;
		while (data[j] < data[i - 1]) {
			j--;
		}
		int temp = data[i - 1];
		data[i - 1] = data[j];
		data[j] = temp;
		Arrays.sort(data, i, data.length);
		return true;
	}

	public static int digit(long n) {
		int result = 0;
		while (n > 0) {
			n /= 10;
			result++;
		}
		return result;
	}

	public static double dist(long a, long b, long x, long y) {
		double val = (b - a) * (b - a) + (x - y) * (x - y);
		val = Math.sqrt(val);
		double other = x * x + a * a;
		other = Math.sqrt(other);
		return val + other;

	}

	public static class Point implements Comparable<Point> {

		int x, y;

		public Point(int start, int end) {
			this.x = start;
			this.y = end;
		}

		@Override
		public int hashCode() {
			int hash = 5;
			hash = 47 * hash + this.x;
			hash = 47 * hash + this.y;
			return hash;
		}

		@Override
		public boolean equals(Object obj) {
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Point other = (Point) obj;
			if (this.x != other.x) {
				return false;
			}
			if (this.y != other.y) {
				return false;
			}
			return true;
		}

		@Override
		public int compareTo(Point o) {
			return x - o.x;
		}
	}

	public static class FT {

		long[] data;

		FT(int n) {
			data = new long[n];
		}

		public void update(int index, long value) {
			while (index < data.length) {
				data[index] += value;
				index += (index & (-index));
			}
		}

		public long get(int index) {
			long result = 0;
			while (index > 0) {
				result += data[index];
				index -= (index & (-index));
			}
			return result;

		}
	}

	public static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	public static long pow(long a, long b) {
		if (b == 0) {
			return 1;
		}
		if (b == 1) {
			return a;
		}
		long val = pow(a, b / 2);
		if (b % 2 == 0) {
			return val * val % MOD;
		} else {
			return val * (val * a % MOD) % MOD;

		}
	}

	static class Scanner {

		BufferedReader br;
		StringTokenizer st;

		public Scanner() throws FileNotFoundException {
			// System.setOut(new PrintStream(new
			// BufferedOutputStream(System.out), true));
			br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new
			// FileInputStream(new File("input.txt"))));
		}

		public String next() {

			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					throw new RuntimeException();
				}
			}
			return st.nextToken();
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			st = null;
			try {
				return br.readLine();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}

		public boolean endLine() {
			try {
				String next = br.readLine();
				while (next != null && next.trim().isEmpty()) {
					next = br.readLine();
				}
				if (next == null) {
					return true;
				}
				st = new StringTokenizer(next);
				return st.hasMoreTokens();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}
	}
}

import java.util.*;
public class C87 {
	public static void main(String[] args){
		Scanner br = new Scanner(System.in);
		int n = br.nextInt();
		int[] preGrundy = new int[n+1];
		for(int i = 1;i<=n;i++){

			int mask = 0;
			for(int j = 2;j<=446;j++){
				int cur = i+(j*(j-1))/2;

				if(cur/j < j) break;
				if(cur%j == 0){
					int res = cur/j;
					if(res >= j){
						int xor = 0;
						xor = preGrundy[res]^preGrundy[res-j];
						mask|=(1<<xor);
					}
					else{
						break;
					}
				}
			}
			int cur = 0;
			for(int j = 0;;j++){
				if((mask & (1<<j)) == 0){
					break;
				}
				cur++;
			}
			preGrundy[i] = preGrundy[i-1]^cur;
		}
		int grundy = preGrundy[n]^preGrundy[n-1];
		if(grundy == 0){
			System.out.println(-1);
		}
		else{
			for(int j = 2;j<n;j++){
				long cur = n+((long)j*(j-1))/2;
				if(cur%j == 0){
					long res = cur/j;
					if(res >= j){
						int xor = 0;
						xor = preGrundy[(int)res]^preGrundy[(int)res-j];
						if(xor == 0){
							System.out.println(j);
							break;
						}
					}
				}
			}
		}
	}
}

//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    static long TIME_START, TIME_END;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.in"));
        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.out.println("Memory increased:" + (usedMemoryAfter-usedMemoryBefore) / 1000000 );
        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    public static class Task {

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int[] psg = new int[n + 1];
            // sg[i] = psg[i] ^ psg[i - 1]
            // ^sg[i...j] = psg[j] ^ psg[i - 1]
            int split = -1;
            for (int i = 3; i <= n; i++) {
                Set<Integer> findLower = new HashSet<>();
                for (int j = 2; j * j + j <= 2 * i; j++) {
                    int from, to;
                    if (j % 2 == 0) {
                        if (i % j == 0 || i % (j / 2) != 0) continue;
                        from = i / j - (j / 2 - 1);
                        to = i / j + (j / 2);
                    } else {
                        if (i % j != 0) continue;
                        from = i / j - (j / 2);
                        to = i / j + (j / 2);
                    }
                    int t = psg[to] ^ psg[from - 1];
                    if (t == 0 && i == n && split == -1) {
                        split = j;
                    }
                    findLower.add(t);
                }
                int j;
                for (j = 0; j < n + 1; j++) {
                    if (!findLower.contains(j)) break;
                }
                psg[i] = j ^ psg[i - 1];
            }
            if ((psg[n] ^ psg[n - 1]) != 0) {
                pw.println(split);
            } else {
                pw.println(-1);
            }
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public Scanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}

        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public double nextDouble() throws IOException { return Double.parseDouble(next()); }

        public boolean ready() throws IOException {return br.ready();}
    }
}

import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    //Into the Hardware Mode
    void pre() throws Exception{}
    void solve(int TC)throws Exception{
        int n = ni();
        int[] grundy = new int[1+n], pre = new int[1+n];
        for(int i = 1; i<= n; i++){
            int sum = 0;
            TreeSet<Integer> set = new TreeSet<>();
            for(int k = 2; k <= i; k++){
                sum += k-1;
                if(sum >= i)break;
                if((i-sum)%k != 0)continue;
                int x = (i-sum)/k;
                set.add(pre[x+k-1]^pre[x-1]);
            }
            for(int x = 0; set.contains(x); x++)grundy[i]++;
            pre[i] = pre[i-1]^grundy[i];
        }
        if(grundy[n] == 0)pn(-1);
        else{
            int sum = 0;
            for(int k = 2; k <= n; k++){
                sum += k-1;
                if(sum >= n)break;
                if((n-sum)%k != 0)continue;
                int x = (n-sum)/k;
                if((pre[x+k-1]^pre[x-1]) == 0){
                    pn(k);
                    return;
                }
            }
        }
    }
    class Point{
        int ind;
        double x, y;
        public Point(int I, double X, double Y){ind = I;x = X;y = Y;}
        public Point(double X, double Y){ind = -1;x = X;y = Y;}
        double dist(Point p){return Math.sqrt((x-p.x)*(x-p.x) + (y-p.y)*(y-p.y));}
    }
    class Segment{
        int ind;
        Point a, b;
        public Segment(int I, Point A, Point B){ind = I;a = A;b = B;}
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    void exit(boolean b){if(!b)System.exit(0);}
    long IINF = (long)1e18, mod = (long)1e9+7;
    final int INF = (int)1e9, MX = (int)2e6+5;
    DecimalFormat df = new DecimalFormat("0.0000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-7;
    static boolean multipleTC = false, memory = false, fileIO = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        if(fileIO){
            in = new FastReader("C:/users/user/desktop/inp.in");
            out = new PrintWriter("C:/users/user/desktop/out.out");
        }else {
            in = new FastReader();
            out = new PrintWriter(System.out);
        }
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();
        for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }

    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str = "";
            try{
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }
            return str;
        }
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CInterestingGame solver = new CInterestingGame();
        solver.solve(1, in, out);
        out.close();
    }

    static class CInterestingGame {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int n = s.nextInt();
            ArrayList<Pair>[] pair = new ArrayList[n + 1];
            for (int i = 1; i <= n; i++)
                pair[i] = new ArrayList<>();
            for (int k = 2; k <= n; k++)
                for (int a = 1; (long) (2 * a + k - 1) * k / 2 <= n; a++)
                    pair[(2 * a + k - 1) * k / 2].add(new Pair(a, k));
            int[] grundy = new int[n + 1];
            int[] val = new int[n + 1];
            Arrays.fill(val, Integer.MAX_VALUE);
            int[] pre = new int[n + 1];
            for (int i = 2; i <= n; i++) {
                HashSet<Integer> hs = new HashSet<>();
                for (Pair p : pair[i]) {
                    hs.add(pre[p.a + p.n - 1] ^ pre[p.a - 1]);
                    if ((pre[p.a + p.n - 1] ^ pre[p.a - 1]) == 0)
                        val[i] = Math.min(p.n, val[i]);
                }
                while (hs.contains(grundy[i]))
                    grundy[i]++;
                pre[i] = grundy[i] ^ pre[i - 1];
            }
            w.println(val[n] != Integer.MAX_VALUE ? val[n] : -1);
        }

        class Pair {
            int a;
            int n;

            Pair(int a, int n) {
                this.a = a;
                this.n = n;
            }

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Abood2D {

	static int n, min[], G[], pG[];

	static int solve(int c) {
		if(G[c] != -1)
			return G[c];

		HashSet<Integer> set = new HashSet<>();

		min[c] = c;

		for (int i = 2, j = 3; j <= c; j += ++i)
			if((c - j) % i == 0) {
				int l = 1 + (c - j) / i;
				int r = i + (c - j) / i;

				int x = pG[r] ^ pG[l - 1];

				if(x == 0)
					min[c] = Math.min(min[c], i);

				set.add(x);
			}

		int ans = 0;
		while(set.contains(ans))ans++;

		return G[c] = ans;

	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();

		G = new int[(int) 1e6 + 1];
		pG = new int[(int) 1e6 + 1];
		min = new int[(int) 1e6 + 1];

		Arrays.fill(G, -1);

		for (int i = 1; i <= n; i++)
			pG[i] = pG[i - 1] ^ solve(i);

		if(G[n] != 0)
			out.println(min[n]);
		else
			out.println(-1);

		out.flush();

	}

	static class Scanner

	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}

	}

}

import java.util.*;
import java.io.*;
import java.math.BigInteger;
import static java.lang.Math.*;

public class Sol implements Runnable {
	ArrayList <Integer> divisors(int n) {
		ArrayList <Integer> ret = new ArrayList <Integer> ();
		for (int i = 1; i * i <= n; i++) {
			if (n % i == 0) {
				ret.add(i);
			}
			if (n % (n / i) == 0 && i * i != n) {
				ret.add(i);
			}
		}
		return ret;
	}

	void solve() throws Exception {
		int n = nextInt();
		int [] arr = new int[n + 1];
		int [] best = new int[n + 1];
		Arrays.fill(best, Integer.MAX_VALUE);
		for (int have = 3; have <= n; have++) {
			ArrayList <Integer> divs = divisors(2 * have);
			HashSet <Integer> trans = new HashSet <Integer> ();
			for (int k: divs) {
				if (k == 1) continue;
				int a2 = (2 * have) / k + 1 - k;
				if (a2 >= 1 && a2 % 2 == 0) {
					int a = a2 / 2;
					int xor = 0;
					for (int i = a; i < a + k; i++) {
						xor ^= arr[i];
					}
					if (xor == 0) {
						best[have] = min(best[have], k);
					}
					trans.add(xor);
				}
			}
			for (int nres = 0; ; nres++) {
				if (!trans.contains(nres)) {
					arr[have] = nres;
					break;
				}
			}
		}

		if (arr[n] == 0) {
			out.println(-1);
			return;
		}

		out.println(best[n]);
	}

	public static void main(String[] args) {
		new Thread(new Sol()).start();
	}

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	StringTokenizer tokenizer = new StringTokenizer("");
	BufferedReader in;
	PrintWriter out;
	long time;

	void sTime() {
		time = System.currentTimeMillis();
	}

	long gTime() {
		return System.currentTimeMillis() - time;
	}

	void gMemory() {
		debug("Memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 + " kb");
	}

	public void debug(Object o) {
		System.err.println(o);
	}

	boolean seekForToken() {
		while (!tokenizer.hasMoreTokens()) {
			String s = null;
			try {
				s = in.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			if (s == null)
				return false;
			tokenizer = new StringTokenizer(s);
		}
		return true;
	}

	String nextToken() {
		return seekForToken() ? tokenizer.nextToken() : null;
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	BigInteger nextBig() {
		return new BigInteger(nextToken());
	}
}

import java.util.*;
import java.io.*;

public class Sol {

	public static void main(String [] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int [] mex = new int[n + 1];
		int [] best = new int[n + 1];
		int [] nxt = new int[n + 1];
		int [] xors = new int[n + 1];
		Arrays.fill(best, Integer.MAX_VALUE);
		for (int have = 3; have <= n; have++) {
			for (int k = 2; k * (k + 1) <= 2 * have; k++) {
				if ((2 * have) % k != 0) continue;
				int a2 = (2 * have) / k + 1 - k;
				if (a2 >= 1 && a2 % 2 == 0) {
					int a = a2 / 2;
					int xor = xors[a + k - 1] ^ xors[a - 1];
					if (xor == 0) {
						best[have] = Math.min(best[have], k);
					}
					nxt[xor] = have;
				}
			}
			for (int nres = 0; ; nres++) {
				if (nxt[nres] != have) {
					mex[have] = nres;
					break;
				}
			}
			xors[have] = xors[have - 1] ^ mex[have];
		}
		out.println(mex[n] != 0 ? best[n] : -1);
		out.close();
	}
}

import java.util.*;
import java.io.*;

public class Sol {
	final static int M = 100000 + 5;
     	static int [] mex = new int[M], best = new int[M], xors = new int[M];
     	static boolean [] done = new boolean[M];

	static void go(int n) {
     		boolean [] used = new boolean[(int)Math.sqrt(2 * n) + 2];
     		for (int k = 2; k * (k + 1) <= 2 * n; k++) {
     			if ((2 * n) % k != 0) continue;
     			int a2 = (2 * n) / k + 1 - k;
     			if (a2 >= 1 && a2 % 2 == 0) {
     				int a = a2 / 2;
     				int xor = 0;
     				for (int i = a; i < a + k; i++) {
     					if (!done[i]) {
     						go(i);
     					}
     					xor ^= mex[i];
     				}
     				if (xor == 0) {
     					best[n] = Math.min(best[n], k);
     				}
     				if (xor < used.length) {
     					used[xor] = true;
     				}
     			}
     		}
     		for (int nres = 0; ; nres++) {
     			if (!used[nres]) {
     				mex[n] = nres;
     				break;
     			}
     		}
     		//xors[n] = xors[n - 1] ^ mex[n];
     		done[n] = true;
	}

	public static void main(String [] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Arrays.fill(best, Integer.MAX_VALUE);
		int n = in.nextInt();
		go(n);
		out.println(mex[n] != 0 ? best[n] : -1);
		out.close();
	}
}

import java.util.*;
import java.io.*;

public class Game {
	 int n;
	 int[] dp = new int[101000];
	 int[] sxor = new int[101000];
	 int[] vis = new int[300];

	 void solve() throws IOException
	 {
		 n = nextInt();
		 sxor[1] = dp[1] = 0; sxor[0] = 0;
		 for(int i = 2; i <= n; ++i) {
			 Arrays.fill(vis, 0);
			 for(int k = 2; k*(k+1) <= 2*i; ++k) {
				 int t = 2 * i / k;
				 if( t * k != 2*i) continue;
				 t += k - 1;
				 if(t % 2 != 0)continue;
				 t /= 2;
				 if(t < k) continue;
				 int tmp = sxor[t]^sxor[t-k];
				 vis[tmp] = 1;
				 if(tmp == 0 && i == n){
					 writer.println(k);
					 break;
				 }
			 }
			 for(dp[i] = 0; vis[dp[i]] > 0; dp[i]++);
			 sxor[i] = sxor[i-1] ^ dp[i];
		 }
		 if(dp[n] == 0)writer.println("-1");
	 }

	 BufferedReader reader;
	 StringTokenizer tokenizer;
	 PrintWriter writer;

	 public static void main(String[] args) throws IOException
	 {
		 new Game().run();
	 }

	 public void run() throws IOException
	 {
		 reader = new BufferedReader(new InputStreamReader(System.in));
		 tokenizer = null;
		 writer = new PrintWriter(System.out);
		 solve();

		 reader.close();
		 writer.close();
	 }

	 int nextInt() throws IOException {
         return Integer.parseInt(nextToken());
     }

     long nextLong() throws IOException {
         return Long.parseLong(nextToken());
     }

     double nextDouble() throws IOException {
         return Double.parseDouble(nextToken());
     }

     String nextToken() throws IOException {
         while (tokenizer == null || !tokenizer.hasMoreTokens()) {
             tokenizer = new StringTokenizer(reader.readLine());
         }
         return tokenizer.nextToken();
     }
}

import java.io.*;
import java.util.*;
import java.math.*;

public class Main implements Runnable {
	final int MAXN = 100000;
	int grundy_cum[] = new int[MAXN+1];

	public void run() {
		int n = nextInt();

		for (int c = 1; c <= n; ++c) {
			ArrayList<Integer> values = new ArrayList<Integer>();

			for (int k = 2; 2*c - k*(k-1) >= 2*k; ++k)
				if ((2*c - k*(k-1)) % (2*k) == 0) {
					int a = (2*c - k*(k-1)) / (2*k);
					values.add(grundy_cum[a+k-1] ^ grundy_cum[a-1]);
				}

			boolean used[] = new boolean[values.size()];
			int mex = values.size();

			for (int i = 0; i < mex; ++i) if (values.get(i) < mex) used[values.get(i)] = true;
			for (int i = 0; i < mex; ++i) if (!used[i]) { mex = i; break; }

			grundy_cum[c] = grundy_cum[c-1] ^ mex;
		}

		if ((grundy_cum[n] ^ grundy_cum[n-1]) == 0) {
			output.println(-1);

		} else {
			for (int k = 2; 2*n - k*(k-1) >= 2*k; ++k)
				if ((2*n - k*(k-1)) % (2*k) == 0) {
					int a = (2*n - k*(k-1)) / (2*k);
					if ((grundy_cum[a+k-1] ^ grundy_cum[a-1]) == 0) { output.println(k); break; }
				}
		}

		output.flush();
	}

    public static void main(String[] args) {
    	//try { input = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); } catch (Exception e) {}
    	new Main().run();
    }

    static BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter output = new PrintWriter(System.out);
    StringTokenizer tokenizer = null;

    int nextInt() {
    	return Integer.parseInt(nextToken());
    }

    long nextLong() {
        return Long.parseLong(nextToken());
    }

    double nextDouble() {
    	return Double.parseDouble(nextToken());
    }

    String nextToken() {
        try
        {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(input.readLine());
            }

            return tokenizer.nextToken();
        } catch (Exception e) {
            return null;
        }
    }
}

import java.util.*;
import java.io.*;

public class C_as {
    FastScanner in;
    PrintWriter out;

    public void solve() throws IOException {
        int n = in.nextInt();

        int[] g = new int[n + 1];
        int[] u = new int[n + 1];
        for (int s = 3; s <= n; s++) {
            for (int k = 2; true; k++) {
                int a = (2 * s + k - k * k) / (2 * k);
                if (a <= 0) {
                    break;
                }
                if ((2 * s + k - k * k) % (2 * k) == 0) {
                    int z = 0;
                    for (int j = 0; j < k; j++) {
                        z = z ^ g[a + j];
                    }
                    u[z] = s;
                }
            }
            while (u[g[s]] == s) {
                g[s]++;
            }
        }

        if (g[n] == 0) {
            out.println(-1);
        } else {
            int s = n;
            for (int k = 2; true; k++) {
                if ((2 * s + k - k * k) % (2 * k) == 0) {
                    int a = (2 * s + k - k * k) / (2 * k);
                    int z = 0;
                    for (int j = 0; j < k; j++) {
                        z = z ^ g[a + j];
                    }
                    if (z == 0) {
                        out.println(k);
                        break;
                    }
                }
            }
        }
    }

    public void run() {
        try {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }

    public static void main(String[] arg) {
        new C_as().run();
    }
}

import java.io.*;
import java.util.*;

public class C {

    void solve() throws IOException {
        in("__std"); out("__std");

        int n = readInt();
        int[] g = new int[n + 1];
        final Set<Integer> w = new HashSet<Integer>();
        int ans = -1;
        for (int v = 3; v <= n; ++v) {
            w.clear();
            for (int k = 2; k * (k + 1) / 2 <= v; ++k) {
                int s = v - k * (k + 1) / 2;
                if (s % k == 0) {
                    s /= k;
                    int r = 0;
                    for (int i = 1; i <= k; ++i) {
                        r ^= g[s + i];
                    }
                    w.add(r);
                    if (v == n && r == 0 && ans == -1) {
                        ans = k;
                    }
                }
            }
            while (w.contains(g[v])) ++g[v];
        }

        println(ans);

        exit();
    }

    void in(String name) throws IOException {
        if (name.equals("__std")) {
            in = new BufferedReader(new InputStreamReader(System.in));
        } else {
            in = new BufferedReader(new FileReader(name));
        }
    }

    void out(String name) throws IOException {
        if (name.equals("__std")) {
            out = new PrintWriter(System.out);
        } else {
            out = new PrintWriter(name);
        }
    }

    void exit() {
        out.close();
        System.exit(0);
    }

    int readInt() throws IOException {
        return Integer.parseInt(readToken());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readToken());
    }

    String readLine() throws IOException {
        st = null;
        return in.readLine();
    }

    String readToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    boolean eof() throws IOException {
        return !in.ready();
    }

    void print(String format, Object ... args) {
        out.println(new Formatter(Locale.US).format(format, args));
    }

    void println(String format, Object ... args) {
        out.println(new Formatter(Locale.US).format(format, args));
    }

    void print(Object value) {
        out.print(value);
    }

    void println(Object value) {
        out.println(value);
    }

    void println() {
        out.println();
    }

    StringTokenizer st;

    BufferedReader in;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        new C().solve();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import static java.lang.Math.*;

public class Main extends Thread {
    public Main() {
        this.tokens = null;
        this.setPriority(Thread.MAX_PRIORITY);
        this.input = new BufferedReader(new InputStreamReader(System.in));
        this.output = new PrintWriter(System.out);
    }

    public void run() {
        try {
            int n = nextInt(), temp;
            int F[] = new int [n + 5];
            int was[] = new int [2 * n];
            int best[] = new int [n + 5];
            int min;
            Arrays.fill(best, Integer.MAX_VALUE);
            Arrays.fill(was, Integer.MIN_VALUE);
            for (int cur = 0; cur <= n; ++cur){
                for (int cnt = 2; cnt * (cnt + 1) / 2 <= cur; ++cnt){
                    int t = cnt * (cnt - 1) / 2;
                    if ((min = cur - t) % cnt != 0){
                        continue;
                    }
                    min /= cnt;
                    int curF = 0;
                    for (int i = 0; i < cnt; ++i){
                        curF ^= F[min + i];
                    }
                    if (curF == 0){
                        best[cur] = min(best[cur], cnt);
                    }
                    was[curF] = cur;
                }
                temp = 0;
                while (was[temp] == cur){
                    ++temp;
                }
                F[cur] = temp;
            }
            output.println((best[n] == Integer.MAX_VALUE )? "-1" : best[n]);
            output.flush();
            output.close();

        } catch (Throwable e) {
            System.err.println(e.getMessage());
            System.err.println(Arrays.deepToString(e.getStackTrace()));
        }
    }

    public static void main(String[] args) {
        new Main().start();
    }

    private String nextToken() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }
    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    private long nextLong() throws IOException{
        return Long.parseLong(nextToken());
    }
    private double nextDouble() throws IOException{
        return Double.parseDouble(nextToken());
    }

    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens;
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import static java.lang.Math.*;

public class Main extends Thread {
    public Main() {
        this.tokens = null;
        this.setPriority(Thread.MAX_PRIORITY);
        this.input = new BufferedReader(new InputStreamReader(System.in));
        this.output = new PrintWriter(System.out);
    }

    public void run() {
        try {
            int n = nextInt(), temp;
            int F[] = new int [n + 5];
            int was[] = new int [2 * n];
            int best[] = new int [n + 5];
            int min;
            Arrays.fill(best, Integer.MAX_VALUE);
            Arrays.fill(was, Integer.MIN_VALUE);
            for (int cur = 0; cur <= n; ++cur){
                for (int cnt = 2; cnt * (cnt + 1) / 2 <= cur; ++cnt){
                    int t = cnt * (cnt - 1) / 2;
                    if ((min = cur - t) % cnt != 0){
                        continue;
                    }
                    min /= cnt;
                    int curF = 0;
                    curF = F[min + cnt -1] ^ F[min - 1];
                    if (curF == 0){
                        best[cur] = min(best[cur], cnt);
                    }
                    was[curF] = cur;
                }
                temp = 0;
                while (was[temp] == cur){
                    ++temp;
                }
                F[cur] = temp;
                if (cur != 0){
                    F[cur] ^= F[cur - 1];
                }
            }
            output.println((best[n] == Integer.MAX_VALUE )? "-1" : best[n]);
            output.flush();
            output.close();

        } catch (Throwable e) {
            System.err.println(e.getMessage());
            System.err.println(Arrays.deepToString(e.getStackTrace()));
        }
    }

    public static void main(String[] args) {
        new Main().start();
    }

    private String nextToken() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }
    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    private long nextLong() throws IOException{
        return Long.parseLong(nextToken());
    }
    private double nextDouble() throws IOException{
        return Double.parseDouble(nextToken());
    }

    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens;
}

import java.util.*;

public class InterestingGame {
    public static void main(String args[]) {
        new InterestingGame();
    }

    public InterestingGame() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        int colors[] = new int[100010];
        colors[1] = 0;
        colors[2] = 0;
        for (int i = 3; i < N; i++) {
            Set<Integer> set = new HashSet<Integer>();
            for (int k = 2; k < 5000; k++) {
                int minSum = k * (k + 1) / 2;
                if (minSum > i)
                    break;
                if ((i - minSum) % k != 0)
                    continue;
                int first = (i - minSum) / k;
                int state = 0;
                for (int j = 1; j <= k; j++) {
                    state ^= colors[j + first];
                }
                set.add(state);
            }
            int x = 0;
            while (set.contains(x)) x++;
            colors[i] = x;
        }
        for (int k = 2; k < 5000; k++) {
            int minSum = k * (k + 1) / 2;
            if (minSum > N)
                break;
            if ((N - minSum) % k != 0)
                continue;
            int first = (N - minSum) / k;
            int state = 0;
            for (int j = 1; j <= k; j++) {
                state ^= colors[j + first];
            }
            if (state == 0) {
                System.out.println(k);
                return;
            }
        }
        System.out.println(-1);
    }
}

import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new Main().run();
				} catch (Throwable e) {
					e.printStackTrace();
					exit(999);
				}
			}
		}, "1", 1 << 23).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	int n, m[];
	int getStart(int count, int sum){
		int ans = 0;
		if( (sum*2) % count == 0 && ( (sum*2) / count - count + 1) % 2 == 0 ){
//			System.err.println("!!! " + ((sum*2) / count - count + 1) / 2 + " " + count + " " + sum);
			ans = ((sum*2) / count - count + 1) / 2;
		}
		if(ans <= 0 || count <= 1)
			return 0;
		return ans;

	}
	int BSum(int a, int b){
		return a^b;
	}
	int getBSum(int a, int c){
		int ans = 0;
		for(int i = a, j = 0; j < c; i++, j++){
			ans = BSum(ans, m[i]);
		}
		return ans;
	}
	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		n = nextInt();

		m = new int [n+1];
		int bans = 0;

		boolean cur[] = new boolean[100];
		for(int i = 0; i <= n; i++){

			bans = 100000;
			int ii = i << 1;
			fill(cur, false);
			int si = (int)sqrt(ii) + 1;
			for(int k = 2; k <= si; k++){
				if(ii % k != 0)
					continue;
				int start = getStart(k, i);
				if (start != 0){
					int dop = getBSum(start, k);
					cur[dop] = true;
					if(dop == 0)
						bans = min(bans, k);
				}
				start = getStart(ii/k, i);
				if (start != 0){
					int dop = getBSum(start, ii/k);
					cur[dop] = true;
					if(dop == 0)
						bans = min(bans, ii/k);
				}
			}
			for(int k = 0; k < 101; k++)
				if(!cur[k]){
					m[i] = k;
					break;
				}
		}
		if(m[n] == 0)
			out.println(-1);
		else
			out.println(bans);
		in.close();
		out.close();
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}

import java.util.InputMismatchException;
import java.math.BigInteger;
import java.io.*;
import java.util.Arrays;

/**
 * Generated by Contest helper plug-in
 * Actual solution is at the bottom
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new StreamInputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		run(in, out);
	}

	public static void run(InputReader in, PrintWriter out) {
		Solver solver = new TaskC();
		solver.solve(1, in, out);
		Exit.exit(in, out);
	}
}

abstract class InputReader {
	private boolean finished = false;

	public abstract int read();

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuffer res = new StringBuffer();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public void setFinished(boolean finished) {
		this.finished = finished;
	}

	public abstract void close();
}

class StreamInputReader extends InputReader {
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar, numChars;

	public StreamInputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public void close() {
		try {
			stream.close();
		} catch (IOException ignored) {
		}
	}
}

class Exit {
	private Exit() {
	}

	public static void exit(InputReader in, PrintWriter out) {
		in.setFinished(true);
		in.close();
		out.close();
	}
}

interface Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out);
}

class TaskC implements Solver {
	public void solve(int testNumber, InputReader in, PrintWriter out) {
		int n = in.readInt();
		int[] nimber = new int[n + 1];
		int[] minimum = new int[n + 1];
		Arrays.fill(minimum, -1);
		int[] value = new int[5 * n];
		for (int i = 3; i <= n; i++) {
			for (int j = 2; j * j < 2 * i; j++) {
				if (2 * i % j == 0) {
					int min = j;
					int max = 2 * i / j;
					if ((max & 1) == (min & 1))
						continue;
					int a = (min + max - 1) >> 1;
					int b = a - min;
					int current = 0;
					for (int k = b + 1; k <= a; k++)
						current ^= nimber[k];
					if (current == 0 && minimum[i] == -1)
						minimum[i] = min;
					value[current] = i;
				}
			}
			for (int j = 0; ; j++) {
				if (value[j] != i) {
					nimber[i] = j;
					break;
				}
			}
		}
		out.println(minimum[n]);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

/**
 * Created by IntelliJ IDEA.
 * User: pashka
 * Date: 05.06.2011
 * Time: 14:02:47
 * To change this template use File | Settings | File Templates.
 */
public class C {
    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        new C().run();
    }

    private void run() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    private void solve() throws IOException {
        int n = nextInt();
        int[] g = new int[n + 1];
        int[] p = new int[n + 1];
        for (int k = 1; k <= n; k++) {
            Set<Integer> set = new HashSet<Integer>();
            for (int z = 2; z * (z + 1) / 2 <= k; z++) {
                int w = k - z * (z + 1) / 2;
                if (w % z == 0) {
                    w /= z;
                    int gg = 0;
                    for (int i = 0; i < z; i++) {
                        gg ^= g[w + i + 1];
                    }
                    if (gg == 0 && p[k] == 0) {
                        p[k] = z;
                    }
                    set.add(gg);
                }
            }
            while (set.contains(g[k])) g[k]++;
        }
        if (g[n] == 0) {
            out.println(-1);
        } else {
            out.println(p[n]);
        }
    }
}

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class problem{

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] res=new int[n+1];
        int[] mini=new int[n+1];
        int[] gr=new int[n+1];
        Arrays.fill(res,0);
        Arrays.fill(mini,Integer.MAX_VALUE);
        Arrays.fill(gr,-1);
        for(int i=3;i<=n;i++)
        {
        	int s=1;
        	for(int j=2;j<=i/2+1;j++)
        	{
        		s+=j;
                if(s>i)break;
                if((i-s)%j!=0)continue;
                int t=(i-s)/j;
                int curres=0;
                for(int k=t+1;k<t+j+1;k++)
                    curres^=res[k];
                gr[curres]=i;
                if(curres==0)mini[i]=Math.min(mini[i],j);
        	}
        	int j=0;
        	while(gr[j]==i)j+=1;
        	res[i]=j;
        }
        if(res[n]>0)System.out.println(mini[n]);
        else System.out.println(-1);
    }

}

import java.io.*;
import java.util.*;

public class Main {
//	static Scanner in;
	static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}
//	static BufferedReader in;
	static PrintWriter out;

	public static void main(String[] args) throws Exception {
//		in = new Scanner(System.in);
		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
//		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		int n = next();

		int[] f = new int[n + 1];
		Arrays.fill(f, -1);
		int[] xr = new int[n + 1];

		f[1] = 0;
		f[0] = 0;
		int[] l = new int[n + 10];
		int ind = 0;
		for (int i = 2; i <= n; i++) {
//			System.out.println(i);
			ind = 0;
			for (int k = 2; k < i; k++) {
				int t = i - k*(k + 1)/2;
				if (t < 0) break;
				if (t % k != 0) continue;
				l[ind++] = xr[t/k + k] ^ xr[t/k];
			}
			boolean[] was = new boolean[ind + 1];
			for (int j = 0; j < ind; j++) if (l[j] <= ind) was[l[j]] = true;
			for (int j = 0; f[i] < 0; j++) if (!was[j]) f[i] = j;
			xr[i] = xr[i - 1] ^ f[i];
		}

		if (f[n] == 0) out.println(-1);
		else {
			for (int k = 2; k < n; k++) {
				int t = n - k*(k + 1)/2;
				if (t % k != 0) continue;
				if ((xr[t/k + k] ^ xr[t/k]) == 0) {
					out.println(k);
					break;
				}
			}
		}

		out.close();
	}
}

import java.util.*;
import java.io.*;

public class Main{

    BufferedReader in;
    StringTokenizer str = null;
    PrintWriter out;

    private String next() throws Exception{
    	while (str == null || !str.hasMoreElements())
    	    str = new StringTokenizer(in.readLine());
    	return str.nextToken();
    }

    private int nextInt() throws Exception{
	   return Integer.parseInt(next());
    }

    int []dp, move;

    public void run() throws Exception{
    	in = new BufferedReader(new InputStreamReader(System.in));
    	out = new PrintWriter(System.out);
        int n = nextInt();

        dp = new int[n + 1];
        Arrays.fill(dp, -1);
        move = new int[n + 1];
        Arrays.fill(move, -1);

        int win = go(n);
        if (win > 0) {
            out.println(move[n]);
        }else {
            out.println(-1);
        }

        out.close();
    }

    private int go(int n) {
        if (dp[n] != -1) {
            return dp[n];
        }

        Set<Integer> set = new HashSet<Integer>();
        for(int i = 2; i * (i + 1) / 2 <= n; ++i) {
            int sum = i * (i + 1) / 2;
            if ((n - sum) % i != 0) continue;
            int xor = 0;
            int first =  (n - sum)/i + 1, last = (n - sum)/i + i;
            for(int j = first; j <= last; ++j) {
                xor^=go(j);
            }
            if (xor == 0) {
                if (move[n] == -1 || move[n] > i) move[n] = i;
            }
            set.add(xor);
        }

        for(int i = 0; ; ++i) {
            if (!set.contains(i)) {
                return dp[n] = i;
            }
        }
    }

    public static void main(String args[]) throws Exception{
	   new Main().run();
    }
}

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class InterestingGame
{
	static int dp[];
	static int[] ans;
	public static void main(String[] args)
	{
		dp = new int[100001];
		ans = new int[100001];
		Arrays.fill(dp, -1);
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(G(n) == 0)
			System.out.println(-1);
		else
			System.out.println(ans[n]);
	}

	private static int G(int n)
	{
		if(dp[n] != -1)
			return dp[n];
		HashSet<Integer> set = new HashSet<Integer>();
		ans[n] = 1000000;
		for (int k = 2;(n - sumto(k-1)) / k > 0; k++)
		{
			if((n - sumto(k-1)) % k == 0)
			{
				int st = (int)((n - sumto(k-1)) / k);
				int xor = 0;
				for (int i = 0; i < k; i++)
					xor ^= G(st++);
				if(xor == 0)
					ans[n] = Math.min(ans[n], k);
				set.add(xor);
			}
		}
		return dp[n] = mex(set);
	}

	static int mex(HashSet<Integer> set)
	{
		int ret = 0;
		while(set.contains(ret))
			ret++;
		return ret;
	}

	static long sumto(int n)
	{
		long n1 = n;
		long n2 = n+1;
		if(n1 % 2 == 0)
			n1 /= 2;
		else
			n2/=2;
		return 1l*n1*n2;
	}
}

import java.io.*;
import java.util.*;

public class E {
	String line = null;
	int max = 100001;
	int[] f = new int[max];

	int[] grundy = new int[max];

	public void run() throws Exception{

		for(int i = 0; i < max; i++){
			grundy[i] = -1;
		}
		grundy[0] = grundy[1] = grundy[2] = 0;

		BufferedReader br = null;
		File file = new File("input.txt");
		if(file.exists()){
			br = new BufferedReader(new FileReader("input.txt"));
		}
		else{
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		line = br.readLine();
		int N = Integer.parseInt(line);

		int t = grundy(N);
		if(t > 0){
			int ans = getAns(N);
			System.out.println(ans);
		}
		else{
			System.out.println("-1");
		}
	}

	int getAns(int n){
		int ans = Integer.MAX_VALUE;
		for(int i = 1; i <= n/2; i++){
			int ret = 0;
			int st = i;
			int sum = 0;
			while(sum < n){
				sum += st;
				st++;
				ret++;
			}
			if(sum == n){
				int gran = 0;
				for(int j = i; j < st; j++){
					gran = gran ^ grundy(j);
				}
				if(gran == 0){
					ans = Math.min(ans, ret);
				}
			}
		}

		return ans;
	}

	int grundy(int n){
		if(grundy[n] != -1){
			return grundy[n];
		}
		if(n == 3){
			System.out.print("");
		}
		List<Integer> set = new ArrayList<Integer>();
		for(int i = 1; i <= n/2; i++){
			int st = i;
			int sum = 0;
			while(sum < n){
				sum += st;
				st++;
			}
			if(sum == n){
				int gran = 0;
				for(int j = i; j < st; j++){
					gran = gran ^ grundy(j);
				}
				set.add(gran);
			}
		}

		int g = 0;
		while(set.contains(g)){
			g++;
		}

		grundy[n] = g;
		return g;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		E t = new E();
		t.run();

	}

}

import java.util.*;
public class e {
public static void main(String[] args)
{
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    ArrayList<Integer>[] lo = new ArrayList[n+1], hi = new ArrayList[n+1];
    for(int i = 0; i<=n; i++)
    {
        lo[i] = new ArrayList<Integer>();
        hi[i] = new ArrayList<Integer>();
    }
    for(int i = 1; i<=n; i++)
    {
        int twopow = 2;
        for(int j = 0; j<20; j++)
        {
            if(i%twopow != 0)
            {
                break;
            }
            twopow *= 2;
        }
        for(int jj = 1; jj<=Math.sqrt(n); jj++)
        {
            int j = jj;
            if(i%j != 0) continue;
            int other = i/j;
            for(int k = 0; k<2; k++)
            {
                if(k==1)
                {
                    if(j==other) break;
                    int temp = j;
                    j = other;
                    other = temp;
                }
                if((j&1) > 0)
                {
                    int center = other;
                    int a = center - j/2, b = center + j/2;
                    if(a>0 && j > 1)
                    {
                        lo[i].add(a);
                        hi[i].add(b);
                    }
                    int j2 = twopow*j;
                    int a2 = i/j2 - (j2/2) + 1;
                    int b2 = i/j2 + j2/2;
                    if(a2 > 0)
                    {
                        lo[i].add(a2);
                        hi[i].add(b2);
                    }
                }
            }
        }
    }
    int[] ans = new int[n+1];
    int[] cxor = new int[n+1];
    int res = -1;
    for(int i = 1;i<=n;i++){
        TreeSet<Integer> xors = new TreeSet<Integer>();
        for(int j = 0;j<lo[i].size();j++){
            int cur = cxor[hi[i].get(j)]^cxor[lo[i].get(j)-1];
            xors.add(cur);
            if(i == n && cur == 0){
                int len = hi[i].get(j)-lo[i].get(j)+1;
                res = (res == -1 ? len : Math.min(len, res));
            }
        }
        int pos = 0;
        for(int j : xors){
            if(j != pos){
                break;
            }
            pos++;
        }
        ans[i] = pos;
        cxor[i] = cxor[i-1]^pos;
    }
    System.out.println(res);
}
}

import java.io.*;
import java.util.*;

public class E implements Runnable{

	BufferedReader in;
	StringTokenizer token = null;

	public int nextInt(){
		try{
			while (token==null || !token.hasMoreElements())
					token = new StringTokenizer(in.readLine());
			return Integer.parseInt(token.nextToken());
		} catch (Exception ex){
			ex.printStackTrace(System.err);
			return Integer.MIN_VALUE;
		}
	}

	public String nextWord(){
		try{
			while (token==null || !token.hasMoreElements())
					token = new StringTokenizer(in.readLine());
			return token.nextToken();
		} catch (Exception ex){
			ex.printStackTrace(System.err);
			return null;
		}
	}

	int[] f, a;
	Set<Integer> set = new TreeSet<Integer>();

	@Override
	public void run() {
		try{
			in = new BufferedReader(new InputStreamReader(System.in));
			int n = nextInt();
			f = new int[n + 5];
			a = new int[n + 5];
			f[1] = f[2] = 0;

			for (int i=3; i<=n; ++i){
				int max = -1;
				set.clear();
				for (int k=2; k<i; ++k){
					int sum = k * (k + 1) / 2;
					if (sum > i) break;
					if ((i - sum) % k != 0) continue;
					int left = 1 + (i - sum) / k;
					int right = k + (i - sum) / k;
					int res = 0;
					for (int j=left; j<=right; ++j)
						res = res ^ f[j];
					set.add(res);
					if (res==0 && max==-1) max = k;
				}
				if (max == -1){
					f[i] = 0;
					continue;
				}
				set.add(1000000);
				int res = 0, prev=-1;
				for (Integer x : set){
					if (x != prev + 1){
						res = prev + 1;
					} else prev = x;
				}
				f[i] = res;
				a[i] = max;
			}

			if (f[n]==0)
				System.out.println(-1); else
				System.out.println(a[n]);
			in.close();
		}catch (Exception ex){

		}
	}

	public static void main(String[] args) {
		(new Thread(new E())).start();
	}
}

import java.io.*;
import java.util.*;

public class E implements Runnable{

	BufferedReader in;
	StringTokenizer token = null;

	public int nextInt(){
		try{
			while (token==null || !token.hasMoreElements())
					token = new StringTokenizer(in.readLine());
			return Integer.parseInt(token.nextToken());
		} catch (Exception ex){
			ex.printStackTrace(System.err);
			return Integer.MIN_VALUE;
		}
	}

	public String nextWord(){
		try{
			while (token==null || !token.hasMoreElements())
					token = new StringTokenizer(in.readLine());
			return token.nextToken();
		} catch (Exception ex){
			ex.printStackTrace(System.err);
			return null;
		}
	}

	int[] f, a;
	int[] xor;
	Set<Integer> set = new TreeSet<Integer>();

	@Override
	public void run() {
		try{
			in = new BufferedReader(new InputStreamReader(System.in));
			int n = nextInt();
			f = new int[n + 5];
			a = new int[n + 5];
			xor = new int[n + 5];
			f[1] = f[2] = 0;
			xor[1] = xor[2] = 0;

			for (int i=3; i<=n; ++i){
				int max = -1;
				set.clear();
				for (int k=2; k<i; ++k){
					int sum = k * (k + 1) / 2;
					if (sum > i) break;
					if ((i - sum) % k != 0) continue;
					int left = 1 + (i - sum) / k;
					int right = k + (i - sum) / k;
					int res = xor[right] ^ xor[left - 1];
					set.add(res);
					if (res==0 && max==-1) max = k;
				}
				if (max == -1){
					f[i] = 0;
					xor[i] = xor[i-1];
					continue;
				}
				set.add(1000000);
				int res = 0, prev=-1;
				for (Integer x : set){
					if (x != prev + 1){
						res = prev + 1;
					} else prev = x;
				}
				f[i] = res;
				a[i] = max;
				xor[i] = xor[i-1] ^ f[i];
			}

			if (f[n]==0)
				System.out.println(-1); else
				System.out.println(a[n]);
			in.close();
		}catch (Exception ex){

		}
	}

	public static void main(String[] args) {
		(new Thread(new E())).start();
	}
}

import java.util.*;
import java.math.*;
public class lucksum {

         static long gcd(long a,long b)
         {
                 if(a>b)
                 {
                         return gcd(b,a);
                 }
                 if(a==0)
                         return b;
                 else
                         return gcd(b%a,a);
         }
         public static void main(String[] args)
        {
               Scanner sc=new Scanner(System.in);
               int n=sc.nextInt();
               int dp[]=new int[n+1];
               int res=-1;
        	   boolean con[]=new boolean[n+1];
               for(int i=3;i<=n;i++)
               {
            	   for(int j=2;j*(j+1)<=2*i;j++)
            	   {

            			   if(2*i%j!=0)
            				   continue;
            			   if((2*i/j+1-j)%2!=0)
            				   continue;
            			   int t=(2*i/j+1-j)/2;
            			   if(t<=0)
            				   continue;
            			   con[dp[t+j-1]^dp[t-1]]=true;

            			   if((i==n)&&((dp[t+j-1]^dp[t-1])==0))
            			   {
            				   res=j;
            				   break;
            			   }
            	   }
            	   int t=0;
            	   for(int j=0;j<=n;j++)
            	   {
            		   if(con[j]==false)
            		   {
            			   t=j;
            			   break;
            		   }
            	   }
            	   dp[i]=t^dp[i-1];
            	   for(int j=0;j*(j+1)<=2*i;j++)
            		   con[j]=false;
               }
               System.out.println(res);
               return;
        }

}
class node implements Comparable<node>{
        public int pre;
        public String name;
        /*public node(long v,long addition)
        {
                mv=v;
                maddition=addition;
        }*/
        public int compareTo(node a)
        {
                return this.pre-a.pre;
        }
}

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class E {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] G = new int[n + 1];
        int[] M = new int[n + 1];
        Arrays.fill(M, Integer.MAX_VALUE);
        for (int i = 3; i <= n; i++) {
            HashSet<Integer> H = new HashSet<Integer>();
            for (int k = 2; k * (k + 1) / 2 <= i; k++) {
                if ((i - k * (k + 1) / 2) % k != 0)
                    continue;
                int start = (i - k * (k + 1) / 2) / k + 1;
                int end = (i - k * (k + 1) / 2) / k + k;
                int xor = 0;
                for (int j = start; j <= end; j++) {
                    xor ^= G[j];
                }
                if (xor == 0)
                    M[i] = Math.min(M[i], k);
                H.add(xor);
            }
            for (int j = 0;; j++)
                if (!H.contains(j)) {
                    G[i] = j;
                    break;
                }
        }
        if (G[n] == 0)
            System.out.println(-1);
        else
            System.out.println(M[n]);
    }
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Saransh
 */
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        try
        {
            Parserdoubt pd=new Parserdoubt(System.in);
            PrintWriter pw=new PrintWriter(System.out);
            int grundies[]=new int[100001];
            int minimums[]=new int[100001];
            Arrays.fill(minimums,Integer.MAX_VALUE);
            //System.out.println(get(3,2));
            for(int i=3;i<=100000;i++)
            {
                int n=(int)(Math.ceil((-1+Math.sqrt(8*i))/2.0))+3;

                HashSet<Integer> set=new HashSet<Integer>();
                for(int j=2;j<=n;j++)
                {
                    int start=get(i,j);

                    if(start>0)
                    {
                        int foset=0;
                        for(int k=0;k<j;k++)
                        {
                            foset^=grundies[k+start];
                        }
                        if(foset==0)
                        {
                            minimums[i]=Math.min(minimums[i], j);

                        }
                        set.add(foset);
                    }
                }
                int chk=0;
                while(true)
                {
                    if(set.contains(chk))
                    {
                        chk++;
                    }
                    else
                    {
                        grundies[i]=chk;
                        break;
                    }
                }
            }

                int input=pd.nextInt();
                if(grundies[input]==0)
                    System.out.println(-1);
                else
                    System.out.println(minimums[input]);

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

    }
    public static int get(int sum,int terms)
    {
        if((2*sum)%terms!=0)
            return -1;
        int tmp=2*sum;
        tmp/=terms;
        tmp=tmp+1-terms;
        if(tmp<0||tmp%2==1)
            return -1;
        return tmp/2;

    }

}

class Parserdoubt
    {
       final private int BUFFER_SIZE = 1 << 17;

       private DataInputStream din;
       private byte[] buffer;
       private int bufferPointer, bytesRead;

       public Parserdoubt(InputStream in)
       {
          din = new DataInputStream(in);
          buffer = new byte[BUFFER_SIZE];
          bufferPointer = bytesRead = 0;
       }
       public String nextString() throws Exception
       {
           StringBuffer sb=new StringBuffer("");
           byte c = read();
           while (c <= ' ') c = read();
           do
           {
               sb.append((char)c);
               c=read();
           }while(c>' ');
           return sb.toString();
       }
       public char nextChar() throws Exception
       {
           byte c=read();
           while(c<=' ') c= read();
           return (char)c;
       }
       public int nextInt() throws Exception
       {
          int ret = 0;
          byte c = read();
          while (c <= ' ') c = read();
          boolean neg = c == '-';
          if (neg) c = read();
          do
          {
              ret = ret * 10 + c - '0';
             c = read();
          } while (c > ' ');
          if (neg) return -ret;
          return ret;
       }
       public long nextLong() throws Exception
       {
          long ret = 0;
          byte c = read();
          while (c <= ' ') c = read();
          boolean neg = c == '-';
          if (neg) c = read();
          do
          {
              ret = ret * 10 + c - '0';
             c = read();
          } while (c > ' ');
          if (neg) return -ret;
          return ret;
       }
       private void fillBuffer() throws Exception
       {
          bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
          if (bytesRead == -1) buffer[0] = -1;
       }

       private byte read() throws Exception
       {
          if (bufferPointer == bytesRead) fillBuffer();
          return buffer[bufferPointer++];
       }
    }

import java.io.BufferedReader;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class C73_div1 {

	static boolean test = false; // System.getProperty("JENS_TURBO") != null;

	public String str() throws IOException {
		if (test) {
			return reader.readLine();
		} else {
			return in.readLine();
		}
	}

	private int in() throws NumberFormatException, IOException {
		return Integer.valueOf(str());
	}

	private long lon() throws NumberFormatException, IOException {
		return Long.valueOf(str());
	}

	private int[] ints() throws Throwable {
		StringTokenizer st = new StringTokenizer(str());

		int[] res = new int[st.countTokens()];
		for (int i = 0; i < res.length; i++) {
			res[i] = Integer.parseInt(st.nextToken());
		}
		return res;
	}

	private long[] longs() throws Throwable {
		StringTokenizer st = new StringTokenizer(str());

		long[] res = new long[st.countTokens()];
		for (int i = 0; i < res.length; i++) {
			res[i] = Long.parseLong(st.nextToken());
		}
		return res;
	}

	private BigInteger[] bigs() throws Throwable {
		StringTokenizer st = new StringTokenizer(str());

		BigInteger[] res = new BigInteger[st.countTokens()];
		for (int i = 0; i < res.length; i++) {
			res[i] = new BigInteger(st.nextToken());
		}
		return res;
	}

	public static void main(String[] args) throws Throwable {
		new C73_div1().solve();
	}

	public C73_div1() throws Throwable {
		if (test) {
			reader = new BufferedReader(new FileReader(new File(testDataFile)));
		}
	}

	static InputStreamReader inp = new InputStreamReader(System.in);
	static BufferedReader in = new BufferedReader(inp);

	static PrintWriter writer = new PrintWriter(System.out);
	static String testDataFile = "testdata.txt";
	BufferedReader reader = null;

	int getseg(int l, int r) {
		return nimsum[r] ^ nimsum[l - 1];
	}

	int maxn = 100020;

	int[] nim = new int[maxn];
	int[] nimsum = new int[maxn];
	int[] minpile = new int[maxn];
	int[] arr = new int[maxn];

	private void solve() throws Throwable, IOException {

		int visid = 0;
		minpile[1] = -1;
		int a = 0, x = 0;
		for (int n = 2; n < maxn; n++) {
			visid++;
			minpile[n] = -1;
			for (int k = 2; k * k < 2 * n; k++) {
				if ((2 * n) % k > 0)
					continue;
				int c = 2 * n / k + 1 - k;
				if (c <= 0 || (c & 1) > 0)
					continue;

				a = c >> 1;
				x = getseg(a, a + k - 1);
				arr[x] = visid;
				if (x == 0 && minpile[n] == -1)
					minpile[n] = k;
			}
			int i = 0;
			for (i = 0; arr[i] == visid; i++);
			nim[n] = i;
			nimsum[n] = nimsum[n - 1] ^ nim[n];
		}
		System.out.println(minpile[in()]);
	}

	private double d(int row, int col, int y, int x) {
		double val = Math.pow(row - y, 2) + Math.pow(col - x, 2);
		return Math.sqrt(val);
	}
}

import java.io.*;
import java.util.*;
import java.math.*;

public class Solution
{

   PrintWriter out;
   BufferedReader in;
   StringTokenizer ss;

   void dbg(String s){System.out.println(s);};
   void deb(String s){System.out.println(s);};
//   void deb(Object... s){System.out.println(s.toString());};

   String _token() throws IOException
   {
    while (!ss.hasMoreTokens())ss=new StringTokenizer(in.readLine());
    return ss.nextToken();
   }

   Double _double() throws IOException
   {
    return Double.parseDouble (_token());
   }

   int _int() throws IOException
   {
    return Integer.parseInt (_token());
   }

   long _long() throws IOException
   {
    return Long.parseLong (_token());
   }

  int N =(int)1e6;

  int best[] = new int[N];
  int val[] = new int[N];

  int fun(int n, int k)
  {
//    deb(n+" "+k);
    n*=2;

    if (k==1)
      return n+1;

    int a = (n/k)+k-1;
    if (a%2==1)
      return n+1;
    a/=2;
    if (a<k)
      return n+1;

//    deb(a+" "+n+" "+k);

    int ans=0;
    for(int i=0;i<k;i++)
      ans^=gr(a-i);
    return ans;
  }

  int gr(int n)
  {
//    deb(n+"");

    if (val[n]!=-1)
      return val[n];

    boolean was[] = new boolean [2*n+2];
    for(int i=1;i*i<=2*n;i++)
    {
      if ((2*n)%i==0)
      {
        was[fun(n,i)]=true;
        was[fun(n,(2*n)/i)]=true;
      }
    }
    int j=0;
    while(was[j])
      j++;
    return val[n]=j;
  }

  void run()throws IOException
  {
    in = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out);
    ss = new StringTokenizer("  ");

    int n;

    for(int i=0;i<N;i++)
      val[i]=-1;

    n=_int();
    if(gr(n)==0)
       out.println(-1);
    else
    {
      for(int k=2;k<=2*n;k++)
        if ((2*n)%k==0)
        if (fun(n,k)==0)
        {
          out.println(k);
          out.close();
          return;
         }
     }
     out.close();
  }

  public static void main(String[] args)throws Exception{
     new Solution().run();
  }

   BigInteger add(BigInteger A, BigInteger B){return A.add(B);}
   BigInteger mult(BigInteger A, BigInteger B){return A.multiply(B);}
   BigInteger sub(BigInteger A, BigInteger B){return A.subtract(B);}
   BigInteger div(BigInteger A, BigInteger B){return A.divide(B);}
   BigInteger mi(BigInteger A){return (BigInteger.ZERO).subtract(A);}
   BigInteger sq(BigInteger A){return A.multiply(A);}
   BigInteger val(long a){return BigInteger.valueOf(a);}
   int cmp(BigInteger a, BigInteger b){return a.compareTo(b);}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.Arrays;

public class C86 {

    static StreamTokenizer in;
    static PrintWriter out;

    static int nextInt() throws IOException {
        in.nextToken();
        return (int)in.nval;
    }

    static String nextString() throws IOException {
        in.nextToken();
        return in.sval;
    }

    public static void main(String[] args) throws IOException {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);

        int n = nextInt();
        int[] nim = new int[n+1];
        int[] sum = new int[n+1];
        int ans = -1;
        boolean[] moves = new boolean[16];
        for (int i = 3; i <= n; i++) {
            long s = 2*i;
            Arrays.fill(moves, false);
            for (long k = 2; (k-1)*k < s; k++) {
                long x = s - (k-1)*k;
                long a = x/(2*k);
                if (a*2*k == x) {
                    long b = a + k - 1;
                    int m = sum[(int)b]^sum[(int)(a-1)];
                    moves[m] = true;
                    if (m == 0 && i == n && ans == -1) {
                        ans = (int)k;
                    }
                }
            }
            for (int j = 0; j < 100; j++)
                if (!moves[j]) {
                    nim[i] = j;
                    break;
                }
            sum[i] = sum[i-1]^nim[i];
        }

        out.println(ans);

        out.flush();
    }
}

import java.io.* ;
import java.util.* ;
import java.math.* ;

public class Main
{
    public static void main( String args[] ) {
        Scanner Input = new Scanner( System.in ) ;
		int SG[] = new int[ 100001 ] ;
		int SUM_SG[] = new int[ 100001 ] ;
		int Ret[] = new int[ 100001 ] ;
		int N = Input.nextInt() ;
		for ( int i = 1 ; i <= N ; i ++ ) {
			boolean H[] = new boolean[ 1001 ] ;
			int M = 2 * i ;
			for ( int k = 2 ; M / k + 1 - k > 0 ; k ++ )
			if ( M % k == 0 && ( M / k + 1 - k ) % 2 == 0 ) {
				int a = ( M / k + 1 - k ) / 2 ;
				int b = a + k - 1 ;
				H[ SUM_SG[ b ] ^ SUM_SG[ a - 1 ] ] = true ;
				if ( H[ 0 ] && Ret[ i ] == 0 ) {
					Ret[ i ] = k ;
				}
			}
			for ( ; H[ SG[ i ] ] ; SG[ i ] ++ ) ;
			SUM_SG[ i ] = SUM_SG[ i - 1 ] ^ SG[ i ] ;
		}
		if ( Ret[ N ] == 0 ) Ret[ N ] = -1 ;
		System.out.println( Ret[ N ] ) ;
    }
}

//package round73;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Scanner;

public class C {
	Scanner in;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int[] u = new int[n+1];
		for(int i = 2;i <= n;i++){
			BitSet bs = new BitSet();
			for(int k = 2;k * k <= 2*i;k++){
				if((2*i-k*(k-1))%(2*k) == 0){
					int b = (2*i-k*(k-1))/(2*k);
					if(b >= 1){
						int x = 0;
						for(int l = b;l <= b+k-1;l++){
							x ^= u[l];
						}
						bs.set(x);
					}
				}
			}
			u[i] = bs.nextClearBit(0);
		}

		if(u[n] == 0){
			out.println(-1);
		}else{
			int i = n;
			for(int k = 2;k * k <= 2*i;k++){
				if((2*i-k*(k-1))%(2*k) == 0){
					int b = (2*i-k*(k-1))/(2*k);
					if(b >= 1){
						int x = 0;
						for(int l = b;l <= b+k-1;l++){
							x ^= u[l];
						}
						if(x == 0){
							out.println(k);
							return;
						}
					}
				}
			}
		}
	}

	void run() throws Exception
	{
		in = oj ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception
	{
		new C().run();
	}

	int ni() { return Integer.parseInt(in.next()); }
	long nl() { return Long.parseLong(in.next()); }
	double nd() { return Double.parseDouble(in.next()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

import java.util.Arrays;
import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] grundy = new int[n + 1];
        int[] seen = new int[n + 4];
        Arrays.fill(seen, -1);
        int minMoves = Integer.MAX_VALUE;
        for (int i = 0; i <= n; i++) {
            for (int count = 2; (count * (count + 1)) / 2 <= i; count++) {
                int rem = i - ((count - 1) * count) / 2;
                if (rem % count != 0)
                    continue;
                int first = rem / count;
                int xor = 0;
                for (int j = 0; j < count; j++) {
                    xor ^= grundy[first + j];
                }
                seen[xor] = i;
                if (xor == 0 && i == n) {
                    minMoves = Math.min(minMoves, count);
                }
            }
            int j = 0;
            for (; seen[j] == i; j++);
            grundy[i] = j;
        }
        if (minMoves == Integer.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(minMoves);
        }
    }
}

import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.regex.*;
import static java.lang.Math.*;
public class C {

    public C() throws Exception {
        int n = in.nextInt();
        int[] grundy = new int[n+1];
        int[] sum = new int[n+1];
        int ans = -1;
        for (int i=1;i<=n;i++) {
            Set<Integer> set = new HashSet<Integer>();
            for (int k=2;;k++) {
                int f = (2*i/k-k+1)/2;
                if (f<=0) break;
                if ((2*f+k-1)*k!=2*i) continue;
                int g = sum[f+k-1]^sum[f-1];
                if (i==n&&g==0) {
                    ans = k;
                    break;
                }
                set.add(g);
            }
            int mex = 0;
            while (set.contains(mex)) mex++;
            grundy[i] = mex;
            sum[i] = sum[i-1]^grundy[i];
        }
        System.out.println(ans);
    }

    Scanner in = new Scanner(System.in);
    StringBuilder buf = new StringBuilder();
    public static void main(String[] args) throws Exception { // {{{
        new C();
    } // }}}
    public static void debug(Object... arr) { // {{{
        System.err.println(Arrays.deepToString(arr));
    } // }}}
    public static class Scanner { // {{{
        BufferedReader br;
        String line;
        StringTokenizer st;
        public Scanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }
        public boolean hasNext() throws IOException {
            while ((st==null||!st.hasMoreTokens())&&(line=br.readLine())!=null)
                st = new StringTokenizer(line);
            return st.hasMoreTokens();
        }
        public String next() throws IOException {
            if (hasNext()) return st.nextToken();
            throw new NoSuchElementException();
        }
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
    } // }}}
}

import java.io.BufferedReader;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class C73_div1 {

	static boolean test = false; // System.getProperty("JENS_TURBO") != null;

	private void solve() throws Throwable, IOException {

		int n = in();
		int[] grundy = new int[n+1];
		int[] seen = new int[n+1];
		int[] minmove = new int[n+1];

		Arrays.fill(seen, -1);
		Arrays.fill(minmove, Integer.MAX_VALUE);

		for (int i = 0; i <= n; i++) {

			for (int k = 2; k * k < i * 2; k++) {

				int triangle = k*(k-1)/2;
				int base = i - triangle;
				if(base % k != 0) continue;
				base /= k;

				int xor = 0;
//				System.out.println(base);

				for (int j = 0; j < k; j++) {
					xor ^= grundy[base + j];
				}
				seen[xor] = i;

				if(xor == 0){
					minmove[i] = Math.min(minmove[i], k);
				}

			}
			int j;
			for (j = 0; seen[j] == i ; j++) ;
			grundy[i] = j;
		}

		if(minmove[n] == Integer.MAX_VALUE){
			System.out.println("-1");
		} else {
			System.out.println(minmove[n]);
		}
	}

	public String str() throws IOException {
		if (test) {
			return reader.readLine();
		} else {
			return in.readLine();
		}
	}

	private int in() throws NumberFormatException, IOException {
		return Integer.valueOf(str());
	}

	private long lo() throws NumberFormatException, IOException {
		return Long.valueOf(str());
	}

	private int[] ints() throws Throwable {
		StringTokenizer st = new StringTokenizer(str());

		int[] res = new int[st.countTokens()];
		for (int i = 0; i < res.length; i++) {
			res[i] = Integer.parseInt(st.nextToken());
		}
		return res;
	}

	private long[] longs() throws Throwable {
		StringTokenizer st = new StringTokenizer(str());

		long[] res = new long[st.countTokens()];
		for (int i = 0; i < res.length; i++) {
			res[i] = Long.parseLong(st.nextToken());
		}
		return res;
	}

	private BigInteger[] bigs() throws Throwable {
		StringTokenizer st = new StringTokenizer(str());

		BigInteger[] res = new BigInteger[st.countTokens()];
		for (int i = 0; i < res.length; i++) {
			res[i] = new BigInteger(st.nextToken());
		}
		return res;
	}

	public static void main(String[] args) throws Throwable {
		new C73_div1().solve();
	}

	public C73_div1() throws Throwable {
		if (test) {
			reader = new BufferedReader(new FileReader(new File(testDataFile)));
		}
	}

	static InputStreamReader inp = new InputStreamReader(System.in);
	static BufferedReader in = new BufferedReader(inp);

	static PrintWriter writer = new PrintWriter(System.out);
	static String testDataFile = "testdata.txt";
	BufferedReader reader = null;

}

//package round73;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C {

	static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
	static PrintWriter out = new PrintWriter(System.out);

	static String nextToken() throws IOException{
		while (st==null || !st.hasMoreTokens()){
			String s = bf.readLine();
			if (s == null)
				return null;
			st = new StringTokenizer(s);
		}

		return st.nextToken();
	}

	static int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException{
		return Long.parseLong(nextToken());
	}

	static String nextStr() throws IOException{
		return nextToken();
	}

	static double nextDouble() throws IOException{
		return Double.parseDouble(nextToken());
	}

	public static void main(String[] args) throws IOException{
		int a[] = new int[100100];
		int res[] = new int[100100];
		int b[] = new int[100100];
		a[1] = a[2] = 0;

		for (int i=3; i<=100000; i++){
			for (int k=2; ; k++){
				int s = (1+k)*k/2;
				if (s > i)
					break;

				if ((i-s)%k == 0){
					int p = (i-s)/k;
					int t = 0;
					for (int j=1; j<=k; j++)
						t ^= a[j+p];

					if (t==0 && res[i]==0)
						res[i] = k;
					b[t] = i;
				}

			}

			for (int j=0; ; j++)
				if (b[j] != i){
					a[i] = j;
					break;
				}
		}

		int n = nextInt();
		if (res[n] == 0)
			out.println("-1");
		else
			out.println(res[n]);
		out.flush();
	}

}

import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main implements Runnable {
	private void solution() throws IOException {
		int n = in.nextInt();
		int[] grandy = new int[n + 1];
		int[] min = new int[n + 1];
		Arrays.fill(min, Integer.MAX_VALUE);
		Arrays.fill(grandy, -1);
		int res = doit(n, grandy, min);
		if (res == 0) {
			out.println(-1);
		} else {
			out.println(min[n]);
		}
	}

	private int doit(int n, int[] grandy, int[] min) {
		if (grandy[n] != -1) {
			return grandy[n];
		}
		Set<Integer> used = new HashSet<Integer>();
		for (int k = 2;; ++k) {
			int minValue = (1 + k) * k / 2;
			if (minValue > n) {
				break;
			}
			if ((n - minValue) % k == 0) {
				int add = (n - minValue) / k;
				int xor = 0;
				for (int i = 0; i < k; ++i) {
					xor ^= doit((i + 1) + add, grandy, min);
				}
				used.add(xor);
				if (xor == 0) {
					min[n] = Math.min(min[n], k);
				}
			}
		}
		for (int res = 0;; ++res) {
			if (!used.contains(res)) {
				return grandy[n] = res;
			}
		}
	}

	public void run() {
		try {
			// try {
			// String fileName = "";
			// in = new Scanner(new FileReader(fileName + ".in"));
			// out = new PrintWriter(fileName + ".out");
			// } catch (Exception e) {
			// }
			solution();
			in.reader.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	private static class Scanner {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		public Scanner(Reader reader) {
			this.reader = new BufferedReader(reader);
			this.tokenizer = new StringTokenizer("");
		}

		public boolean hasNext() throws IOException {
			while (!tokenizer.hasMoreTokens()) {
				String line = reader.readLine();
				if (line == null) {
					return false;
				}
				tokenizer = new StringTokenizer(line);
			}
			return true;
		}

		public String next() throws IOException {
			hasNext();
			return tokenizer.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			tokenizer = new StringTokenizer("");
			return reader.readLine();
		}

		public int[] nextInts(int n) throws IOException {
			int[] res = new int[n];
			for (int i = 0; i < n; ++i) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongs(int n) throws IOException {
			long[] res = new long[n];
			for (int i = 0; i < n; ++i) {
				res[i] = nextLong();
			}
			return res;
		}

		public double[] nextDoubles(int n) throws IOException {
			double[] res = new double[n];
			for (int i = 0; i < n; ++i) {
				res[i] = nextDouble();
			}
			return res;
		}

		public String[] nextStrings(int n) throws IOException {
			String[] res = new String[n];
			for (int i = 0; i < n; ++i) {
				res[i] = next();
			}
			return res;
		}
	}

	public static void main(String[] args) throws Exception {
		new Thread(null, new Main(), "Main", 1 << 28).start();
	}
	private Scanner in = new Scanner(new InputStreamReader(System.in));
	private PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
}

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskC {

    int canWin(int n){
        int div = 2;

        while(true){
            if(((long)div * (div - 1)) / 2 >= n) break;

            int x = n - (int)(((long)div * (div - 1)) / 2);

            if(x % div == 0){
                x /= div;
                int cnt = 0;
                for(int start = 0; start < div; start++){
                    if(canWin(x + start) != -1){
                       cnt++;
                    }
                }
                if(cnt % 2 == 0) return div;
            }
            div++;
            continue;
        }

        return -1;
    }

    void run(){
        int n = nextInt();

        int[] res = new int[n + 1];
        Arrays.fill(res, -1);
        int[] grundy = new int[n + 1];

        HashSet<Integer> set = new HashSet<Integer>();
        for(int i = 3; i <= n; i++){
            set.clear();
            for(int div = 2; ((long)div * (div - 1)) / 2 < i; div++){
                int x = i - (int)((long) div * (div - 1) / 2);
                if(x % div == 0){
                    x /= div;
                    int xor = 0;
                    for(int start = 0; start < div; start++)
                        xor ^= grundy[x + start];
                    set.add(xor);
                    if(xor == 0 && res[i] == -1)
                        res[i] = div;
                }
            }
            int r = 0;
            while(set.contains(r))r++;
            grundy[i] = r;
        }

        System.out.println(res[n]);
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new TaskC().run();
    }
}

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskC {

    int canWin(int n){
        int div = 2;

        while(true){
            if(((long)div * (div - 1)) / 2 >= n) break;

            int x = n - (int)(((long)div * (div - 1)) / 2);

            if(x % div == 0){
                x /= div;
                int cnt = 0;
                for(int start = 0; start < div; start++){
                    if(canWin(x + start) != -1){
                       cnt++;
                    }
                }
                if(cnt % 2 == 0) return div;
            }
            div++;
            continue;
        }

        return -1;
    }

    void run(){
        int n = nextInt();

        int[] res = new int[n + 1];
        Arrays.fill(res, -1);
        int[] grundy = new int[n + 1];

        HashSet<Integer> set = new HashSet<Integer>();
        for(int i = 3; i <= n; i++){
            set.clear();
            for(int div = 2; div * (div - 1) / 2 < i; div++){
                int x = i - div * (div - 1) / 2;
                if(x % div == 0){
                    x /= div;
                    int xor = 0;
                    for(int start = 0; start < div; start++)
                        xor ^= grundy[x + start];
                    set.add(xor);
                    if(xor == 0 && res[i] == -1)
                        res[i] = div;
                }
            }
            int r = 0;
            while(set.contains(r))r++;
            grundy[i] = r;
        }

        System.out.println(res[n]);
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new TaskC().run();
    }
}

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskC {

    void run(){
        int n = nextInt();

        int[] res = new int[n + 1];
        Arrays.fill(res, -1);
        int[] grundy = new int[n + 1];

        HashSet<Integer> set = new HashSet<Integer>();
        for(int i = 3; i <= n; i++){
            set.clear();
            for(int div = 2; div * (div - 1) / 2 < i; div++){
                int x = i - div * (div - 1) / 2;
                if(x % div == 0){
                    x /= div;
                    int xor = 0;
                    for(int start = 0; start < div; start++)
                        xor ^= grundy[x + start];
                    set.add(xor);
                    if(xor == 0 && res[i] == -1)
                        res[i] = div;
                }
            }
            int r = 0;
            while(set.contains(r))r++;
            grundy[i] = r;
        }

        System.out.println(res[n]);
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new TaskC().run();
    }
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.lang.Double.*;
import static java.math.BigInteger.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable {

	private void solve() throws IOException {
//		long start = System.currentTimeMillis();
		init();
		readData();
		processing();
//		System.err.println(System.currentTimeMillis() - start);
	}

	private void init() {
	}

	HashSet<Integer> si = new HashSet<Integer>();

	private int mex(List<Integer> lst) {
		si.clear();
		si.addAll(lst);
		int ret = 0;
		while (si.contains(ret)) {
			++ret;
		}
		return ret;
	}

	private void processing() {
		int[] nim = new int[MAXN];
		nim[0] = nim[1] = nim[2] = 0;
		List<Integer> fg = new ArrayList<Integer>();
		Map<Integer, Integer> firstTurn = new Hashtable<Integer, Integer>();
		for (int i = 3; i < 100001; ++i) {
			fg.clear();
			int memo = -1;
			for (int j = 2; j*j <= 2*i; ++j) {
				if (2*i%j == 0) {
					int n = 2*i/j - 1 + j;
					if (n%2 == 0) {
						n /= 2;
						if (n - j + 1 > 0) {
							int xor = 0;
							for (int l = n; l > n-j; --l) {
								xor ^= nim[l];
							}
							if (xor == 0 && memo == -1) {
								memo = j;
								firstTurn.put(i, memo);
							}
							fg.add(xor);
						}
					}
				}
			}
			nim[i] = mex(fg);
		}
		if (nim[nn] == 0) {
			println(-1);
		}
		else {
			println(firstTurn.get(nn));
		}
	}

	private void readData() throws IOException {
		nn = nextInt();
	}

	private int nn;

	private static final int MAXN = 100001;

	public static void main(String[] args) throws InterruptedException {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().run();
			}
		}, "1", 1 << 24).start();
	}

	// @Override
	public void run() {
		try {
			boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
			reader = onlineJudge ? new BufferedReader(new InputStreamReader(
					System.in)) : new BufferedReader(
					new FileReader("input.txt"));
			writer = onlineJudge ? new PrintWriter(new BufferedWriter(
					new OutputStreamWriter(System.out))) : new PrintWriter(
					new BufferedWriter(new FileWriter("output.txt")));
			Locale.setDefault(Locale.US);
			tokenizer = null;
			solve();
			writer.flush();
		} catch (Exception error) {
			error.printStackTrace();
			System.exit(1);
		}
	}

	class InputReader {

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		private InputStream stream;
		private byte[] buf = new byte[1 << 16];
		private int curChar;
		private int numChars;
	}

	private class Parser {

		public Parser(InputStream in) {
			din = new DataInputStream(in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public byte c;

		public int nextInt() throws IOException {
			int value = 0;
			c = read();
			while (c <= ' ')
				c = read();
			boolean neg = c == '-';
			if (neg)
				c = read();
			do {
				value = value * 10 + c - 48;
				c = read();
			} while (c > ' ');
			if (neg) {
				return -value;
			} else {
				return value;
			}
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		public byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		final private int BUFFER_SIZE = 1 << 16;
	}

	private BufferedReader reader;
	private PrintWriter writer;
	private StringTokenizer tokenizer;

	private void println() {
		writer.println();
	}

	private void print(Object obj) {
		writer.print(obj);
	}

	private void println(Object obj) {
		writer.println(obj);
	}

	private void printf(String f, Object... obj) {
		writer.printf(f, obj);
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.lang.Double.*;
import static java.math.BigInteger.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable {

	// private long start;

	private void solve() throws IOException {
		// start = System.currentTimeMillis();
		init();
		readData();
		processing();
	}

	private void init() {
	}

	HashSet<Integer> si = new HashSet<Integer>();

	private int mex(List<Integer> lst) {
		si.clear();
		si.addAll(lst);
		int ret = 0;
		while (si.contains(ret)) {
			++ret;
		}
		return ret;
	}

	private void processing() {
		int[] nim = new int[MAXN];
		int[] xnim = new int[MAXN];
		nim[0] = nim[1] = nim[2] = 0;
		xnim[0] = xnim[1] = xnim[2] = 0;
		List<Integer> fg = new ArrayList<Integer>();
		Map<Integer, Integer> firstTurn = new Hashtable<Integer, Integer>();
		for (int i = 3; i < 100001; ++i) {
			fg.clear();
			int memo = -1;
			for (int j = 2; j*j <= 2*i; ++j) {
				if (2*i%j == 0) {
					int n = 2*i/j - 1 + j;
					if (n%2 == 0) {
						n /= 2;
						if (n - j + 1 > 0) {
							int xor = xnim[n]^xnim[n-j];
							if (xor == 0 && memo == -1) {
								memo = j;
								firstTurn.put(i, memo);
							}
							fg.add(xor);
						}
					}
				}
			}
			nim[i] = mex(fg);
			xnim[i] = xnim[i-1]^nim[i];
		}
		if (nim[nn] == 0) {
			println(-1);
		}
		else {
			println(firstTurn.get(nn));
		}
	}

	private void readData() throws IOException {
		nn = nextInt();
	}

	private int nn;

	private static final int MAXN = 100001;

	public static void main(String[] args) throws InterruptedException {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().run();
			}
		}, "1", 1 << 24).start();
	}

	// @Override
	public void run() {
		try {
			boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
			reader = onlineJudge ? new BufferedReader(new InputStreamReader(
					System.in)) : new BufferedReader(
					new FileReader("input.txt"));
			writer = onlineJudge ? new PrintWriter(new BufferedWriter(
					new OutputStreamWriter(System.out))) : new PrintWriter(
					new BufferedWriter(new FileWriter("output.txt")));
			Locale.setDefault(Locale.US);
			tokenizer = null;
			solve();
			writer.flush();
		} catch (Exception error) {
			error.printStackTrace();
			System.exit(1);
		}
	}

	class InputReader {

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		private InputStream stream;
		private byte[] buf = new byte[1 << 16];
		private int curChar;
		private int numChars;
	}

	private class Parser {

		public Parser(InputStream in) {
			din = new DataInputStream(in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public byte c;

		public int nextInt() throws IOException {
			int value = 0;
			c = read();
			while (c <= ' ')
				c = read();
			boolean neg = c == '-';
			if (neg)
				c = read();
			do {
				value = value * 10 + c - 48;
				c = read();
			} while (c > ' ');
			if (neg) {
				return -value;
			} else {
				return value;
			}
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		public byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		final private int BUFFER_SIZE = 1 << 16;
	}

	private BufferedReader reader;
	private PrintWriter writer;
	private StringTokenizer tokenizer;

	private void println() {
		writer.println();
	}

	private void print(Object obj) {
		writer.print(obj);
	}

	private void println(Object obj) {
		writer.println(obj);
	}

	private void printf(String f, Object... obj) {
		writer.printf(f, obj);
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.lang.Double.*;
import static java.math.BigInteger.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable {

	// private long start;

	private void solve() throws IOException {
		// start = System.currentTimeMillis();
		init();
		readData();
		processing();
	}

	private void init() {
	}

	HashSet<Integer> si = new HashSet<Integer>();

	private int mex(List<Integer> lst) {
		si.clear();
		si.addAll(lst);
		int ret = 0;
		while (si.contains(ret)) {
			++ret;
		}
		return ret;
	}

	private void processing() {
		nim = new int[100001];
		nim[0] = nim[1] = nim[2] = 0;
		List<Integer> fg = new ArrayList<Integer>();
		Map<Integer, Integer> firstTurn = new Hashtable<Integer, Integer>();
		for (int i = 3; i < 100001; ++i) {
			fg.clear();
			int memo = -1;
			for (int j = 2; j*j <= 2*i; ++j) {
				if (2*i%j == 0) {
					int n = 2*i/j - 1 + j;
					if (n%2 == 0) {
						n /= 2;
						if (n - j + 1 > 0) {
							int xor = 0;
							for (int l = n; l >= n - j + 1; --l) {
								xor ^= nim[l];
							}
							if (xor == 0 && memo == -1) {
								memo = j;
								firstTurn.put(i, memo);
							}
							fg.add(xor);
						}
					}
				}
			}
			nim[i] = mex(fg);
		}
		if (nim[nn] == 0) {
			println(-1);
		}
		else {
			println(firstTurn.get(nn));
		}
	}

	private void readData() throws IOException {
		nn = nextInt();
	}

	private int nn;

	private int[] nim;

	public static void main(String[] args) throws InterruptedException {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().run();
			}
		}, "1", 1 << 24).start();
	}

	// @Override
	public void run() {
		try {
			boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
			reader = onlineJudge ? new BufferedReader(new InputStreamReader(
					System.in)) : new BufferedReader(
					new FileReader("input.txt"));
			writer = onlineJudge ? new PrintWriter(new BufferedWriter(
					new OutputStreamWriter(System.out))) : new PrintWriter(
					new BufferedWriter(new FileWriter("output.txt")));
			Locale.setDefault(Locale.US);
			tokenizer = null;
			solve();
			writer.flush();
		} catch (Exception error) {
			error.printStackTrace();
			System.exit(1);
		}
	}

	class InputReader {

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		private InputStream stream;
		private byte[] buf = new byte[1 << 16];
		private int curChar;
		private int numChars;
	}

	private class Parser {

		public Parser(InputStream in) {
			din = new DataInputStream(in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public byte c;

		public int nextInt() throws IOException {
			int value = 0;
			c = read();
			while (c <= ' ')
				c = read();
			boolean neg = c == '-';
			if (neg)
				c = read();
			do {
				value = value * 10 + c - 48;
				c = read();
			} while (c > ' ');
			if (neg) {
				return -value;
			} else {
				return value;
			}
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		public byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		final private int BUFFER_SIZE = 1 << 16;
	}

	private BufferedReader reader;
	private PrintWriter writer;
	private StringTokenizer tokenizer;

	private void println() {
		writer.println();
	}

	private void print(Object obj) {
		writer.print(obj);
	}

	private void println(Object obj) {
		writer.println(obj);
	}

	private void printf(String f, Object... obj) {
		writer.printf(f, obj);
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.lang.Double.*;
import static java.math.BigInteger.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable {

	// private long start;

	private void solve() throws IOException {
		// start = System.currentTimeMillis();
		init();
		readData();
		processing();
	}

	private void init() {
	}

	HashSet<Integer> si = new HashSet<Integer>();

	private int mex(List<Integer> lst) {
		si.clear();
		si.addAll(lst);
		int ret = 0;
		while (si.contains(ret)) {
			++ret;
		}
		return ret;
	}

	private void processing() {
		nim = new int[100001];
		nim[0] = 0;
		nim[1] = 0;
		nim[2] = 0;
		nim[3] = 1;
		List<Integer> fg = new ArrayList<Integer>();
		int[] firstTurn = new int[100001];
		firstTurn[3] = 2;
		for (int i = 4; i < 100001; ++i) {
			fg.clear();
			int memo = -1;
			for (int j = 2; j*j <= 2*i; ++j) {
				if (2*i%j == 0) {
					int n = 2*i/j - 1 + j;
					if (n%2 == 0) {
						n /= 2;
						if (n - j + 1 > 0) {
							int xor = 0;
							for (int l = n; l >= n - j + 1; --l) {
								xor ^= nim[l];
							}
							if (xor == 0 && memo == -1) {
								memo = j;
							}
							fg.add(xor);
						}
					}
				}
			}
			nim[i] = mex(fg);
			firstTurn[i] = memo;
		}
		if (nim[nn] == 0) {
			println(-1);
		}
		else {
			println(firstTurn[nn]);
		}
	}

	private void readData() throws IOException {
		nn = nextInt();
	}

	private int nn;

	private int[] nim;

	public static void main(String[] args) throws InterruptedException {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().run();
			}
		}, "1", 1 << 24).start();
	}

	// @Override
	public void run() {
		try {
			boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
			reader = onlineJudge ? new BufferedReader(new InputStreamReader(
					System.in)) : new BufferedReader(
					new FileReader("input.txt"));
			writer = onlineJudge ? new PrintWriter(new BufferedWriter(
					new OutputStreamWriter(System.out))) : new PrintWriter(
					new BufferedWriter(new FileWriter("output.txt")));
			Locale.setDefault(Locale.US);
			tokenizer = null;
			solve();
			writer.flush();
		} catch (Exception error) {
			error.printStackTrace();
			System.exit(1);
		}
	}

	class InputReader {

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		private InputStream stream;
		private byte[] buf = new byte[1 << 16];
		private int curChar;
		private int numChars;
	}

	private class Parser {

		public Parser(InputStream in) {
			din = new DataInputStream(in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public byte c;

		public int nextInt() throws IOException {
			int value = 0;
			c = read();
			while (c <= ' ')
				c = read();
			boolean neg = c == '-';
			if (neg)
				c = read();
			do {
				value = value * 10 + c - 48;
				c = read();
			} while (c > ' ');
			if (neg) {
				return -value;
			} else {
				return value;
			}
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		public byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		final private int BUFFER_SIZE = 1 << 16;
	}

	private BufferedReader reader;
	private PrintWriter writer;
	private StringTokenizer tokenizer;

	private void println() {
		writer.println();
	}

	private void print(Object obj) {
		writer.print(obj);
	}

	private void println(Object obj) {
		writer.println(obj);
	}

	private void printf(String f, Object... obj) {
		writer.printf(f, obj);
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * Author -
 * User: kansal
 * Date: 6/7/11
 * Time: 11:55 PM
 */
public class Game {
    public static void main(String[] args) {
        reader = new BufferedReader(new InputStreamReader(System.in));

        int n = nextInt();
        int[] sum = new int[501];
        for(int i = 1; i <= 500; ++i) {
            sum[i] = i + sum[i-1];
            if (sum[i] >= 100000) {
                sum[i] = 100500;
            }
        }

        int[] gruindy = new int[n+1];
        int[] state = new int[n+1];
        for(int i = 3; i <= n; ++i) {
            for(int j = 1; sum[j] < i; ++j) {
                int f = (i - sum[j]) / (j + 1);
                if (f * (j+1) != (i-sum[j])) {
                    continue;
                }
                int g = 0;
                for(int k = f; k <= f+j; ++k) {
                    g ^= gruindy[k];
                }
                state[g] = i;
                if (i == n && g == 0) {
                    System.out.println(j+1);
                    return;
                }
            }
            for(int j = 0; j <= n; ++j) {
                if (state[j] != i) {
                    gruindy[i] = j;
                    break;
                }
            }
        }

        System.out.println(-1);
    }

    public static BufferedReader reader;

    public static StringTokenizer tokenizer = null;

    static String nextToken() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    static public int nextInt() {
        return Integer.parseInt(nextToken());
    }

    static public String next() {
        return nextToken();
    }

    static public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}

import java.io.*;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.fill;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.sort;

public class Main {
	public static void main(String[] args) throws IOException {
		new Thread(null, new Runnable() {
			public void run() {
				try {
					try {
						if (new File("input.txt").exists())
							System.setIn(new FileInputStream("input.txt"));
					} catch (SecurityException e) {}
					new Main().run();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}, "1", 1L << 24).start();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");

	int MAX = 100000;
	int[] xor = new int [MAX + 1];
	int[] mex = new int [MAX + 1];

	void run() throws IOException {
		int[] tmp = new int [1000];
		for (int i = 1; i < mex.length; i++) {
			int sz = 0;
			int di = i << 1;
			for (int k = 2; k * k <= di; k++) {
				if (di % k == 0) {
					int g1 = get(di, k); if (g1 >= 0) tmp[sz++] = g1;
					int g2 = get(di, di / k); if (g2 >= 0) tmp[sz++] = g2;
				}
			}

			sort(tmp, 0, sz);

			if (sz == 0 || tmp[0] > 0) {
				mex[i] = 0;
			} else {
				boolean ok = false;
				for (int j = 1; j < sz; j++)
					if (tmp[j] - tmp[j - 1] > 1) {
						mex[i] = tmp[j - 1] + 1;
						ok = true;
						break;
					}
				if (!ok) mex[i] = tmp[sz - 1] + 1;
			}
			xor[i] = xor[i - 1] ^ mex[i];
		}

		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		int n = nextInt();
		if (mex[n] == 0) {
			out.println(-1);
		} else {
			int dn = n << 1;
			for (int k = 2; ; k++) {
				if (dn % k == 0 && get(dn, k) == 0) {
					out.println(k);
					break;
				}
			}
		}

		out.close();
	}

	int get(int dn, int k) {
		int num = dn / k - k + 1;
		if ((num & 1) == 1) return -1;
		int af = num >> 1;
		if (af <= 0) return -1;
		int al = af + k - 1;
//		System.out.println(af + " " + al + " " + k + " " + dn / 2 + " " + (xor[al] ^ xor[af - 1]));
		return xor[al] ^ xor[af - 1];
	}

	int xor(int l, int r) {
		return xor[r] ^ xor[l - 1];
	}

	/***************************************************************
	 * Input
	 **************************************************************/
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}

	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}

import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;

public class Contest73_3 {
    public static int []gr;
    public static LinkedList<Point> getNums(int num){
        LinkedList<Point> res = new LinkedList<Point>();
        for (int i = 2; (i*(i+1)/2)<=num; i++) {
            int rem = num-(i*(i+1)/2);
            if(rem%i==0){
                int st = (rem/i) + 1;
                int en = st+i-1;
                res.add(new Point(st,en));
            }
        }
        return res;
    }
    public static int grundy(int n){
        if(n==0 || n==1 || n==2)
            return 0;
        if(gr[n]!=-1)
           return gr[n];
        LinkedList<Point> curr = getNums(n);
        HashSet<Integer> s = new HashSet<Integer>();
        for (Point i : curr) {
            int st = i.x;
            int en = i.y;
            int xor = 0;
            for (int j = st; j <= en; j++) {
                xor = xor ^ grundy(j);
            }
            s.add(xor);
        }
        for (int i = 0;; i++) {
            if(!s.contains(i))
                return gr[n] = i;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        gr = new int [n+1];
        Arrays.fill(gr,-1);
        grundy(n);
        int res = -1;
        LinkedList<Point> curr = getNums(n);
        HashSet<Integer> s = new HashSet<Integer>();
        for (Point i : curr) {
            int st = i.x;
            int en = i.y;
            int x = 0;
            for (int j = st; j <= en; j++) {
                x = x ^ gr[j];
            }
            if(x==0){
                res = en-st+1;
                break;
            }
        }
        System.out.println(res);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Game implements Runnable {
    private void solve() throws IOException {
        int n = nextInt();
        int[] grundy = new int[n + 1];
        int[] seen = new int[n + 2];
        int[] minMoves = new int[n + 1];
        Arrays.fill(minMoves, Integer.MAX_VALUE);
        Arrays.fill(seen, -1);
        for (int i = 0; i <= n; ++i) {
            for (int count = 2; count * (count + 1) / 2 <= i; ++count) {
                int first = (i - (count * (count - 1)) / 2);
                if (first % count != 0) continue;
                first /= count;
                int xor = 0;
                for (int j = 0; j < count; ++j) xor ^= grundy[first + j];
                seen[xor] = i;
                if (xor == 0) minMoves[i] = Math.min(minMoves[i], count);
            }
            int j;
            for (j = 0; seen[j] == i; ++j);
            grundy[i] = j;
        }
        if (minMoves[n] == Integer.MAX_VALUE)
            writer.println(-1);
        else
            writer.println(minMoves[n]);
    }

    public static void main(String[] args) {
        new Game().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class CF_Div1_73_C {

    static int INFINITY = 2000000000;

    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        sc = new StringTokenizer("");

        int n = nxtInt();
        System.out.println(calc(n));

    }// end Main.

    public static int calc(int n) {

        HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
        for (int k = 0; k < Math.sqrt(2 * n); k++) {
            double x = 2 * n - Math.pow(k, 2);
            double y = (double) x / k;
            y += 1;
            y /= 2;
            int a = (int) y;
            if (a == y) {
                int xorValue = 0;
                for (int j = 0; j < k; j++) {
                    xorValue = xorValue ^ (a + j);
                }// end for(j).
                map.put(xorValue, k);
            }
        }// end for(k).

        int i = 0;
        while (!map.containsKey(i)) {
            i++;

        }
        if (i == 0) {
            return -1;
        }
        return map.get(i);
    }

    static BufferedReader br;
    static StringTokenizer sc;
    static PrintWriter out;

    static String nxtTok() throws IOException {
        while (!sc.hasMoreTokens()) {
            String s = br.readLine();
            if (s == null)
                return null;
            sc = new StringTokenizer(s.trim());
        }
        return sc.nextToken();
    }

    static int nxtInt() throws IOException {
        return Integer.parseInt(nxtTok());
    }

    static long nxtLng() throws IOException {
        return Long.parseLong(nxtTok());
    }

    static double nxtDbl() throws IOException {
        return Double.parseDouble(nxtTok());
    }

    static int[] nxtIntArr(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nxtInt();
        return a;
    }

    static long[] nxtLngArr(int n) throws IOException {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nxtLng();
        return a;
    }

    static char[] nxtCharArr() throws IOException {
        return nxtTok().toCharArray();
    }

}// end class

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] SG = new int[n + 1];
        int[] xorPrefix = new int[n + 1];
        int record = -1;
        for (int i = 1; i <= n; i++) {
            List<Integer> list = new ArrayList<Integer>();
            list.add(Integer.MAX_VALUE);
            for (int k = 1; k <= i; k++) {
                int up = n + n + k - k * k;
                int down = 2 * k;
                if (up <= 0) {
                    break;
                }
                if (up % down != 0) {
                    continue;
                }
                int a = up / down;
                int value = xorPrefix[a - 1] ^ xorPrefix[a + k - 1];
                list.add(value);
                if (i == n && value == 0) {
                    record = k;
                }
            }
            Collections.sort(list);
            for (int j = 0; j < list.size() - 1; j++) {
                if (list.get(j) + 1 < list.get(j + 1)) {
                    SG[i] = list.get(j) + 1;
                    break;
                }
            }
            xorPrefix[i] = xorPrefix[i - 1] ^ SG[i];
        }
        if (SG[n] == 0) {
            System.out.println(-1);
        } else {
            System.out.println(record);
        }
    }
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] SG = new int[n + 1];
        int[] xorPrefix = new int[n + 1];
        int record = Integer.MAX_VALUE;
        for (int i = 1; i <= n; i++) {
            List<Integer> list = new ArrayList<Integer>();
            list.add(Integer.MAX_VALUE);
            list.add(-1);
            for (int k = 1; k <= i; k++) {
                int up = n + n + k - k * k;
                int down = 2 * k;
                if (up <= 0) {
                    break;
                }
                if (up % down != 0) {
                    continue;
                }
                int a = up / down;
                int value = xorPrefix[a - 1] ^ xorPrefix[a + k - 1];
                list.add(value);
                if (i == n && value == 0) {
                    record = Math.min(record, k);
                }
            }
            Collections.sort(list);
            for (int j = 0; j < list.size() - 1; j++) {
                if (list.get(j) + 1 < list.get(j + 1)) {
                    SG[i] = list.get(j) + 1;
                    break;
                }
            }
            xorPrefix[i] = xorPrefix[i - 1] ^ SG[i];
        }
        if (SG[n] == 0) {
            System.out.println(-1);
        } else {
            System.out.println(record);
        }
    }
}

import java.util.ArrayList;
import java.util.Scanner;

//http://codeforces.com/problemset/problem/87/C
public class InterestingGame {
	private static boolean[] winning;

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		winning = new boolean[n + 1];
		SequenceList[] waysToSum = new SequenceList[n + 1];
		for (int i = 0; i < waysToSum.length; i++) {
			waysToSum[i] = new SequenceList();
		}
		for (int startEl = 1; startEl <= n / 2; startEl++) {
			int max = startEl + 1;
			int sum = startEl + max;
			while (sum <= n) {
				waysToSum[sum].addSeq(startEl, max);
				max++;
				sum += max;
			}
		}
		for (int i = 0; i < winning.length; i++) {
			winning[i] = minWinning(i, waysToSum[i]) > 0;
		}
		System.out.println(minWinning(n,waysToSum[n]));
		s.close();
	}

	private static int minWinning(int n, SequenceList s) {
		int minPileSplit = Integer.MAX_VALUE;
		for (int i = 0; i < s.min.size(); i++) {
			int winningSubPositions = 0;
			for (int j = s.min.get(i); j <= s.max.get(i); j++) {
				if (winning[j]) {
					winningSubPositions++;
				}
			}
			if (winningSubPositions % 2 == 0) {
				minPileSplit = Math.min(minPileSplit, s.max.get(i) - s.min.get(i) + 1);
			}
		}
		if (minPileSplit == Integer.MAX_VALUE) {
			minPileSplit = -1;
		}
		return minPileSplit;
	}

	public static class SequenceList {
		ArrayList<Integer> min = new ArrayList<Integer>();
		ArrayList<Integer> max = new ArrayList<Integer>();

		public void addSeq(int min, int max) {
			this.min.add(min);
			this.max.add(max);
		}
	}
}

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//http://codeforces.com/problemset/problem/87/C
public class InterestingGame2 {
	private static int[] grundy;
	// xorGrundy[i] contains grundy[0]^grundy[1]^grundy[2]^...^grundy[i]
	private static int[] xorGrundy;
	private static SequenceList[] waysToSumTo;

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		grundy = new int[n + 1];
		xorGrundy = new int[n + 1];
		grundy[0] = 0;
		xorGrundy[0] = 0;
		waysToSumTo = new SequenceList[n + 1];
		for (int i = 0; i < waysToSumTo.length; i++) {
			waysToSumTo[i] = new SequenceList();
		}
		// add in each way that you can sum up to a number
		for (int startEl = 1; startEl <= n / 2; startEl++) {
			int max = startEl + 1;
			int sum = startEl + max;
			while (sum <= n) {
				waysToSumTo[sum].addSeq(startEl, max);
				max++;
				sum += max;
			}
		}
		for (int i = 1; i < grundy.length; i++) {
			grundy[i] = getGrundy(i);
			xorGrundy[i] = xorGrundy[i - 1] ^ grundy[i];
		}
		if (grundy[n] == 0) {
			System.out.println(-1);
		} else {
			SequenceList waysToSum = waysToSumTo[n];
			int minLength = Integer.MAX_VALUE;
			for (int i = 0; i < waysToSum.length; i++) {
				if (waysToSum.seqLength(i) < minLength && waysToSum.xorSequence(i) == 0) {
					minLength = waysToSum.seqLength(i);
				}
			}
			System.out.println(minLength);
		}
		s.close();
	}

	private static int getGrundy(int n) {
		SequenceList waysToSum = waysToSumTo[n];
		Set<Integer> posGrundy = new HashSet<>();
		for (int i = 0; i < waysToSum.length; i++) {
			posGrundy.add(waysToSum.xorSequence(i));
		}
		return MEX(posGrundy);
	}

	private static int MEX(Set<Integer> vals) {
		for (int i = 0; i <= vals.size(); i++) {
			if (!vals.contains(i)) {
				return i;
			}
		}
		return -1;
	}

	public static class SequenceList {
		private ArrayList<Integer> min = new ArrayList<Integer>();
		private ArrayList<Integer> max = new ArrayList<Integer>();
		int length = 0;

		public void addSeq(int min, int max) {
			this.min.add(min);
			this.max.add(max);
			length++;
		}

		public int seqLength(int i) {
			return max.get(i) - min.get(i) + 1;
		}

		public int xorSequence(int i) {
			int seqMin = min.get(i);
			int seqMax = max.get(i);
			return xorGrundy[seqMax] - xorGrundy[seqMin - 1];
		}

		@Override
		public String toString() {
			String ret = "{";
			for (int i = 0; i < min.size(); i++) {
				ret = ret + min.get(i) + " " + max.get(i) + ", ";
			}
			return ret + "}";
		}
	}
}

//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    static long TIME_START, TIME_END;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.in"));
        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.out.println("Memory increased:" + (usedMemoryAfter-usedMemoryBefore) / 1000000 );
        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    public static class Task {

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int[] psg = new int[n + 1];
            psg[1] = 1; // sg[i] = psg[i] ^ psg[i - 1]
                        // ^sg[i...j] = psg[j] ^ psg[i - 1]
            psg[2] = 0;
            int split = -1;
            for (int i = 3; i <= n; i++) {
                Set<Integer> findLower = new HashSet<>();
                for (int j = 2; j * j + j <= 2 * i; j++) {
                    int from, to;
                    if (j % 2 == 0) {
                        if (i % j == 0 || i % (j / 2) != 0) continue;
                        from = i / j - (j / 2 - 1);
                        to = i / j + (j / 2);
                    } else {
                        if (i % j != 0) continue;
                        from = i / j - (j / 2);
                        to = i / j + (j / 2);
                    }
                    int t = psg[to] ^ psg[from - 1];
                    if (t == 0 && i == n) split = j;
                    findLower.add(t);
                }
                int j;
                for (j = 0; j < n + 1; j++) {
                    if (!findLower.contains(j)) break;
                }
                psg[i] = j ^ psg[i - 1];
            }
            if (psg[n] != 0) {
                pw.println(split);
            } else {
                pw.println(-1);
            }
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public Scanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}

        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public double nextDouble() throws IOException { return Double.parseDouble(next()); }

        public boolean ready() throws IOException {return br.ready();}
    }
}

//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    static long TIME_START, TIME_END;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.in"));
        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.out.println("Memory increased:" + (usedMemoryAfter-usedMemoryBefore) / 1000000 );
        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    public static class Task {

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int[] psg = new int[n + 1];
            psg[1] = 1; // sg[i] = psg[i] ^ psg[i - 1]
                        // ^sg[i...j] = psg[j] ^ psg[i - 1]
            psg[2] = 0;
            int split = -1;
            for (int i = 3; i <= n; i++) {
                Set<Integer> findLower = new HashSet<>();
                for (int j = 2; j * j + j <= 2 * i; j++) {
                    int from, to;
                    if (j % 2 == 0) {
                        if (i % j == 0 || i % (j / 2) != 0) continue;
                        from = i / j - (j / 2 - 1);
                        to = i / j + (j / 2);
                    } else {
                        if (i % j != 0) continue;
                        from = i / j - (j / 2);
                        to = i / j + (j / 2);
                    }
                    if (from == 0) continue;
                    if (to - from != j - 1) continue;
                    if ((from + to) * j / 2 != n) continue;
                    int t = psg[to] ^ psg[from - 1];
                    if (t == 0 && i == n && split == -1) split = j;
                    findLower.add(t);
                }
                int j;
                for (j = 0; j < n + 1; j++) {
                    if (!findLower.contains(j)) break;
                }
                psg[i] = j ^ psg[i - 1];
            }
            if (psg[n] != 0) {
                pw.println(split);
            } else {
                pw.println(-1);
            }
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public Scanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}

        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public double nextDouble() throws IOException { return Double.parseDouble(next()); }

        public boolean ready() throws IOException {return br.ready();}
    }
}

//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    static long TIME_START, TIME_END;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.in"));
        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.out.println("Memory increased:" + (usedMemoryAfter-usedMemoryBefore) / 1000000 );
        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    public static class Task {

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int[] psg = new int[n + 1];
            psg[1] = 1; // sg[i] = psg[i] ^ psg[i - 1]
                        // ^sg[i...j] = psg[j] ^ psg[i - 1]
            psg[2] = 0;
            int split = -1;
            for (int i = 3; i <= n; i++) {
                Set<Integer> findLower = new HashSet<>();
                for (int j = 2; j * j + j <= 2 * i; j++) {
                    int from, to;
                    if (j % 2 == 0) {
                        if (i % j == 0 || i % (j / 2) != 0) continue;
                        from = i / j - (j / 2 - 1);
                        to = i / j + (j / 2);
                    } else {
                        if (i % j != 0) continue;
                        from = i / j - (j / 2);
                        to = i / j + (j / 2);
                    }
                    int t = psg[to] ^ psg[from - 1];
                    if (t == 0 && i == n && split == -1) {
                        split = j;
                    }
                    findLower.add(t);
                }
                int j;
                for (j = 0; j < n + 1; j++) {
                    if (!findLower.contains(j)) break;
                }
                psg[i] = j ^ psg[i - 1];
            }
            if ((psg[n] ^ psg[n - 1]) != 0) {
                pw.println(split);
            } else {
                pw.println(-1);
            }
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public Scanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}

        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public double nextDouble() throws IOException { return Double.parseDouble(next()); }

        public boolean ready() throws IOException {return br.ready();}
    }
}

//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    static long TIME_START, TIME_END;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.in"));
        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.out.println("Memory increased:" + (usedMemoryAfter-usedMemoryBefore) / 1000000 );
        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    public static class Task {

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int[] psg = new int[n + 1];
            psg[1] = 1; // sg[i] = psg[i] ^ psg[i - 1]
                        // ^sg[i...j] = psg[j] ^ psg[i - 1]
            psg[2] = 0;
            int split = -1;
            for (int i = 3; i <= n; i++) {
                Set<Integer> findLower = new HashSet<>();
                for (int j = 2; j * j + j <= 2 * i; j++) {
                    int from, to;
                    if (j % 2 == 0) {
                        if (i % j == 0 || i % (j / 2) != 0) continue;
                        from = i / j - (j / 2 - 1);
                        to = i / j + (j / 2);
                    } else {
                        if (i % j != 0) continue;
                        from = i / j - (j / 2);
                        to = i / j + (j / 2);
                    }
                    int t = psg[to] ^ psg[from - 1];
                    if (t == 0 && i == n && split == -1) split = j;
                    findLower.add(t);
                }
                int j;
                for (j = 0; j < n + 1; j++) {
                    if (!findLower.contains(j)) break;
                }
                psg[i] = j ^ psg[i - 1];
            }
            if (psg[n] != 0) {
                pw.println(split);
            } else {
                pw.println(-1);
            }
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public Scanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {return Integer.parseInt(next());}

        public long nextLong() throws IOException {return Long.parseLong(next());}

        public String nextLine() throws IOException {return br.readLine();}

        public double nextDouble() throws IOException { return Double.parseDouble(next()); }

        public boolean ready() throws IOException {return br.ready();}
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;

import javax.print.attribute.HashDocAttributeSet;

import java.util.StringTokenizer;

public class Abood2D {

	static int n, min[], G[], pG[];

	static int solve(int c) {
		if(G[c] != -1)
			return G[c];

		HashSet<Integer> set = new HashSet<>();

		min[c] = c;

		for (int i = 2, j = 3; j < c; i++, j += i++)
			if((c - j) % i == 0) {
				int l = 1 + (c - j) / i;
				int r = i + (c - j) / i;

				int x = pG[r] ^ pG[l - 1];

				if(x == 0)
					min[c] = Math.min(min[c], i);

				set.add(x);
			}

		int ans = 0;
		while(set.contains(ans))ans++;

		return G[c] = ans;

	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();

		G = new int[(int) 1e6 + 1];
		pG = new int[(int) 1e6 + 1];
		min = new int[(int) 1e6 + 1];

		Arrays.fill(G, -1);

		for (int i = 1; i <= n; i++)
			pG[i] = pG[i - 1] ^ solve(i);

		if(G[n] == 0)
			out.println(min[n]);
		else
			out.println(-1);

		out.flush();

	}

	static class Scanner

	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}

	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;

import javax.print.attribute.HashDocAttributeSet;

import java.util.StringTokenizer;

public class Abood2D {

	static int n, min[], G[], pG[];

	static int solve(int c) {
		if(G[c] != -1)
			return G[c];

		HashSet<Integer> set = new HashSet<>();

		min[c] = c;

		for (int i = 2, j = 3; j <= c; i++, j += ++i)
			if((c - j) % i == 0) {
				int l = 1 + (c - j) / i;
				int r = i + (c - j) / i;

				int x = pG[r] ^ pG[l - 1];

				if(x == 0)
					min[c] = Math.min(min[c], i);

				set.add(x);
			}

		int ans = 0;
		while(set.contains(ans))ans++;

		return G[c] = ans;

	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();

		G = new int[(int) 1e6 + 1];
		pG = new int[(int) 1e6 + 1];
		min = new int[(int) 1e6 + 1];

		Arrays.fill(G, -1);

		for (int i = 1; i <= n; i++)
			pG[i] = pG[i - 1] ^ solve(i);

		if(G[n] != 0)
			out.println(min[n]);
		else
			out.println(-1);

		out.flush();

	}

	static class Scanner

	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}

	}

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;

import javax.print.attribute.HashDocAttributeSet;

import java.util.StringTokenizer;

public class Abood2D {

	static int n, min[], G[], pG[];

	static int solve(int c) {
		if(G[c] != -1)
			return G[c];

		HashSet<Integer> set = new HashSet<>();

		min[c] = c;

		for (int i = 2, j = 3; j <= c; i++, j += i++)
			if((c - j) % i == 0) {
				int l = 1 + (c - j) / i;
				int r = i + (c - j) / i;

				int x = pG[r] ^ pG[l - 1];

				if(x == 0)
					min[c] = Math.min(min[c], i);

				set.add(x);
			}

		int ans = 0;
		while(set.contains(ans))ans++;

		return G[c] = ans;

	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();

		G = new int[(int) 1e6 + 1];
		pG = new int[(int) 1e6 + 1];
		min = new int[(int) 1e6 + 1];

		Arrays.fill(G, -1);

		for (int i = 1; i <= n; i++)
			pG[i] = pG[i - 1] ^ solve(i);

		if(G[n] != 0)
			out.println(min[n]);
		else
			out.println(-1);

		out.flush();

	}

	static class Scanner

	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}

	}

}

import java.util.*;
import java.io.*;
import java.math.BigInteger;
import static java.lang.Math.*;

public class Sol implements Runnable {
	ArrayList <Integer> divisors(int n) {
		ArrayList <Integer> ret = new ArrayList <Integer> ();
		for (int i = 1; i * i <= n; i++) {
			if (n % i == 0) {
				ret.add(i);
			}
			if (n % (n / i) == 0 && i * i != n) {
				ret.add(i);
			}
		}
		return ret;
	}

	void solve() throws Exception {
		int n = nextInt();
		int [] arr = new int[n + 1];
		arr[1] = 0;
		arr[2] = 0;
		int [] best = new int[n + 1];
		Arrays.fill(best, Integer.MAX_VALUE);
		for (int have = 3; have <= n; have++) {
			ArrayList <Integer> divs = divisors(2 * have);
			HashSet <Integer> trans = new HashSet <Integer> ();
			for (int k: divs) {
				if (k == 1) continue;
				int a2 = (2 * have) / k + 1 - k;
				if (a2 >= 1 && a2 % 2 == 0) {
					int a = a2 / 2;
					int xor = 0;
					for (int i = a; i < a + k; i++) {
						xor ^= arr[i];
					}
					if (xor == 0) {
						best[have] = min(best[have], k);
					}
					trans.add(xor);
				}
			}
			for (int nres = 0; ; nres++) {
				if (!trans.contains(nres)) {
					arr[have] = nres;
					break;
				}
			}
		}

		if (arr[n] == 0) {
			out.println(-1);
			return;
		}

		out.println(best[n]);
	}

	public static void main(String[] args) {
		new Thread(new Sol()).start();
	}

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();

			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	StringTokenizer tokenizer = new StringTokenizer("");
	BufferedReader in;
	PrintWriter out;
	long time;

	void sTime() {
		time = System.currentTimeMillis();
	}

	long gTime() {
		return System.currentTimeMillis() - time;
	}

	void gMemory() {
		debug("Memory: " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 + " kb");
	}

	public void debug(Object o) {
		System.err.println(o);
	}

	boolean seekForToken() {
		while (!tokenizer.hasMoreTokens()) {
			String s = null;
			try {
				s = in.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			if (s == null)
				return false;
			tokenizer = new StringTokenizer(s);
		}
		return true;
	}

	String nextToken() {
		return seekForToken() ? tokenizer.nextToken() : null;
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}

	BigInteger nextBig() {
		return new BigInteger(nextToken());
	}
}

import java.util.*;
import java.io.*;

public class Sol {

	public static void main(String [] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int [] mex = new int[n + 1];
		int [] best = new int[n + 1];
		int [] nxt = new int[n + 1];
		int [] xors = new int[n + 1];
		Arrays.fill(best, Integer.MAX_VALUE);
		for (int have = 3; have <= n; have++) {
			for (int k = 2; k * (k + 1) <= 2 * have; k++) {
				if ((2 * have) % k != 0) continue;
				int a2 = (2 * have) / k + 1 - k;
				if (a2 >= 1 && a2 % 2 == 0) {
					int a = a2 / 2;
					int xor = xors[a + k - 1] ^ xors[a - 1];
					if (xor == 0) {
						best[have] = Math.min(best[have], k);
					}
					nxt[xor] = have;
				}
			}
			for (int nres = 0; ; nres++) {
				if (nxt[nres] != have) {
					mex[have] = nres;
					break;
				}
			}
			xors[have] = xors[have - 1] ^ mex[have];
		}
		if (mex[n] == 0) {
			out.println(-1);
			return;
		}
		out.println(best[n]);
		out.close();
	}
}

import java.util.*;
import java.io.*;

public class Game {
	 int n;
	 int[] dp = new int[101000];
	 int[] sxor = new int[101000];

	 void solve() throws IOException
	 {
		 n = nextInt();
		 sxor[1] = dp[1] = 0; sxor[0] = 0;
		 for(int i = 2; i <= n; ++i) {
			 dp[i] = 0;
			 for(int k = 2; k*(k+1) <= 2*i; ++k) {
				 int t = 2 * i / k;
				 if( t * k != 2*i) continue;
				 t += k - 1;
				 if(t % 2 != 0)continue;
				 t /= 2;
				 if(t < k) continue;
				 if((sxor[t] ^ sxor[t-k]) == 0) {
					 dp[i] = 1;
					 if(i == n) {
						 writer.println(k);
					 }
					 break;
				 }
			 }
			 sxor[i] = sxor[i-1] ^ dp[i];
		 }
		 if(dp[n] == 0)writer.println("-1");
	 }

	 BufferedReader reader;
	 StringTokenizer tokenizer;
	 PrintWriter writer;

	 public static void main(String[] args) throws IOException
	 {
		 new Game().run();
	 }

	 public void run() throws IOException
	 {
		 reader = new BufferedReader(new InputStreamReader(System.in));
		 tokenizer = null;
		 writer = new PrintWriter(System.out);
		 solve();

		 reader.close();
		 writer.close();
	 }

	 int nextInt() throws IOException {
         return Integer.parseInt(nextToken());
     }

     long nextLong() throws IOException {
         return Long.parseLong(nextToken());
     }

     double nextDouble() throws IOException {
         return Double.parseDouble(nextToken());
     }

     String nextToken() throws IOException {
         while (tokenizer == null || !tokenizer.hasMoreTokens()) {
             tokenizer = new StringTokenizer(reader.readLine());
         }
         return tokenizer.nextToken();
     }
}

import java.util.*;
import java.io.*;

public class Game {
	 int n;
	 int[] dp = new int[101000];
	 int[] sxor = new int[101000];

	 void solve() throws IOException
	 {
		 n = nextInt();
		 sxor[1] = dp[1] = 0;
		 for(int i = 2; i <= n; ++i) {
			 dp[i] = 0;
			 for(int k = 2; k*(k+1) <= 2*i; ++k) {
				 int t = 2 * i / k;
				 if( t * k != 2*i) continue;
				 t += k - 1;
				 if(t % 2 != 0)continue;
				 t /= 2;
				 if((sxor[t] ^ sxor[t-k]) == 0) {
					 dp[i] = 1;
					 if(i == n) {
						 writer.println(k);
					 }
					 break;
				 }
			 }
			 sxor[i] = sxor[i-1] ^ dp[i];
		 }
		 if(dp[n] == 0)writer.println("-1");
	 }

	 BufferedReader reader;
	 StringTokenizer tokenizer;
	 PrintWriter writer;

	 public static void main(String[] args) throws IOException
	 {
		 new Game().run();
	 }

	 public void run() throws IOException
	 {
		 reader = new BufferedReader(new InputStreamReader(System.in));
		 tokenizer = null;
		 writer = new PrintWriter(System.out);
		 solve();

		 reader.close();
		 writer.close();
	 }

	 int nextInt() throws IOException {
         return Integer.parseInt(nextToken());
     }

     long nextLong() throws IOException {
         return Long.parseLong(nextToken());
     }

     double nextDouble() throws IOException {
         return Double.parseDouble(nextToken());
     }

     String nextToken() throws IOException {
         while (tokenizer == null || !tokenizer.hasMoreTokens()) {
             tokenizer = new StringTokenizer(reader.readLine());
         }
         return tokenizer.nextToken();
     }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import static java.lang.Math.*;

public class Main extends Thread {
    public Main() {
        this.tokens = null;
        this.setPriority(Thread.MAX_PRIORITY);
        this.input = new BufferedReader(new InputStreamReader(System.in));
        this.output = new PrintWriter(System.out);
    }

    public void run() {
        try {
            int n = nextInt(), temp;
            int F[] = new int [n + 5];
            int was[] = new int [n + 5];
            int best[] = new int [n + 5];
            Arrays.fill(best, n + 1);
            Arrays.fill(was, -1);
            for (int cur = 0; cur <= n; ++cur){
                for (int cnt = 2; cnt * (cnt + 1) <= cur; ++cnt){
                    int t = cnt * (cnt - 1) / 2;
                    int first = cur - t;
                    if (first % cnt != 0){
                        continue;
                    }
                    first /= cnt;
                    int curF = 0;
                    for (int i = 0; i < cnt; ++i){
                        curF ^= F[first + i];
                    }
                    if (curF == 0){
                        best[cur] = min(best[cur], cnt);
                    }
                    was[curF] = cur;
                }
                temp = 0;
                while (temp <= n && was[temp] != cur){
                    ++temp;
                }
                F[cur] = temp;
            }
            output.println(best[n] == n + 1 ? "-1" : best[n]);
            output.flush();
            output.close();

        } catch (Throwable e) {
            System.err.println(e.getMessage());
            System.err.println(Arrays.deepToString(e.getStackTrace()));
        }
    }

    public static void main(String[] args) {
        new Main().start();
    }

    private String nextToken() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }
    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    private long nextLong() throws IOException{
        return Long.parseLong(nextToken());
    }
    private double nextDouble() throws IOException{
        return Double.parseDouble(nextToken());
    }

    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens;
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import static java.lang.Math.*;

public class Main extends Thread {
    public Main() {
        this.tokens = null;
        this.setPriority(Thread.MAX_PRIORITY);
        this.input = new BufferedReader(new InputStreamReader(System.in));
        this.output = new PrintWriter(System.out);
    }

    public void run() {
        try {
            int n = nextInt(), temp;
            int F[] = new int [n + 5];
            SortedSet<Integer> was  = new TreeSet<Integer>();
            int best[] = new int [n + 5];
            Arrays.fill(best, Integer.MAX_VALUE);
            for (int cur = 0; cur <= n; ++cur){
                for (int cnt = 2; cnt * (cnt + 1) / 2 <= cur; ++cnt){
                    int t = cnt * (cnt - 1) / 2;
                    int first = cur - t;
                    if (first % cnt != 0){
                        continue;
                    }
                    first /= cnt;
                    int curF = 0;
                    for (int i = 0; i < cnt; ++i){
                        curF ^= F[first + i];
                    }
                    if (curF == 0){
                        best[cur] = min(best[cur], cnt);
                    }
                    was.add(cur);
                }
                if (was.isEmpty()){
                    temp = 0;
                }
                else{
                    temp = was.first();
                }
                F[cur] = temp;
            }
            output.println((best[n] == Integer.MAX_VALUE )? "-1" : best[n]);
            output.flush();
            output.close();

        } catch (Throwable e) {
            System.err.println(e.getMessage());
            System.err.println(Arrays.deepToString(e.getStackTrace()));
        }
    }

    public static void main(String[] args) {
        new Main().start();
    }

    private String nextToken() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }
    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    private long nextLong() throws IOException{
        return Long.parseLong(nextToken());
    }
    private double nextDouble() throws IOException{
        return Double.parseDouble(nextToken());
    }

    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens;
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import static java.lang.Math.*;

public class Main extends Thread {
    public Main() {
        this.tokens = null;
        this.setPriority(Thread.MAX_PRIORITY);
        this.input = new BufferedReader(new InputStreamReader(System.in));
        this.output = new PrintWriter(System.out);
    }

    public void run() {
        try {
            int n = nextInt(), temp;
            int F[] = new int [n + 5];
            int was[] = new int [2 * n];
            int best[] = new int [n + 5];
            int min;
            if (n % 2 == 0){
                output.println(-1);
                return;
            }
            Arrays.fill(best, Integer.MAX_VALUE);
            Arrays.fill(was, Integer.MIN_VALUE);
            for (int cur = 0; cur <= n; ++cur){
                for (int cnt = 2; cnt * (cnt + 1) / 2 <= cur; ++cnt){
                    int t = cnt * (cnt - 1) / 2;
                    if ((min = cur - t) % cnt != 0){
                        continue;
                    }
                    min /= cnt;
                    int curF = 0;
                    curF = F[min + cnt -1] ^ F[min - 1];
                    if (curF == 0){
                        best[cur] = min(best[cur], cnt);
                    }
                    was[curF] = cur;
                }
                temp = 0;
                while (was[temp] == cur){
                    ++temp;
                }
                F[cur] = temp;
                if (cur != 0){
                    F[cur] ^= F[cur - 1];
                }
            }
            output.println((best[n] == Integer.MAX_VALUE )? "-1" : best[n]);
            output.flush();
            output.close();

        } catch (Throwable e) {
            System.err.println(e.getMessage());
            System.err.println(Arrays.deepToString(e.getStackTrace()));
        }
    }

    public static void main(String[] args) {
        new Main().start();
    }

    private String nextToken() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }
    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    private long nextLong() throws IOException{
        return Long.parseLong(nextToken());
    }
    private double nextDouble() throws IOException{
        return Double.parseDouble(nextToken());
    }

    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens;
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import static java.lang.Math.*;

public class Main extends Thread {
    public Main() {
        this.tokens = null;
        this.setPriority(Thread.MAX_PRIORITY);
        this.input = new BufferedReader(new InputStreamReader(System.in));
        this.output = new PrintWriter(System.out);
    }

    public void run() {
        try {
            int n = nextInt(), temp;
            int F[] = new int [n + 5];
            int was[] = new int [2 * n];
            int best[] = new int [n + 5];
            int min;
            if (n > 1000 && n % 2 == 0){
                output.println(-1);
                return;
            }
            Arrays.fill(best, Integer.MAX_VALUE);
            Arrays.fill(was, Integer.MIN_VALUE);
            for (int cur = 0; cur <= n; ++cur){
                for (int cnt = 2; cnt * (cnt + 1) / 2 <= cur; ++cnt){
                    int t = cnt * (cnt - 1) / 2;
                    if ((min = cur - t) % cnt != 0){
                        continue;
                    }
                    min /= cnt;
                    int curF = 0;
                    curF = F[min + cnt -1] ^ F[min - 1];
                    if (curF == 0){
                        best[cur] = min(best[cur], cnt);
                    }
                    was[curF] = cur;
                }
                temp = 0;
                while (was[temp] == cur){
                    ++temp;
                }
                F[cur] = temp;
                if (cur != 0){
                    F[cur] ^= F[cur - 1];
                }
            }
            output.println((best[n] == Integer.MAX_VALUE )? "-1" : best[n]);
            output.flush();
            output.close();

        } catch (Throwable e) {
            System.err.println(e.getMessage());
            System.err.println(Arrays.deepToString(e.getStackTrace()));
        }
    }

    public static void main(String[] args) {
        new Main().start();
    }

    private String nextToken() throws IOException {
        while (tokens == null || !tokens.hasMoreTokens()) {
            tokens = new StringTokenizer(input.readLine());
        }
        return tokens.nextToken();
    }
    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    private long nextLong() throws IOException{
        return Long.parseLong(nextToken());
    }
    private double nextDouble() throws IOException{
        return Double.parseDouble(nextToken());
    }

    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens;
}

import java.io.*;
import java.util.*;

public class E {
	String line = null;
	int max = 100001;
	int[] f = new int[max];

	int[] grundy = new int[max];

	public void run() throws Exception{

		for(int i = 0; i < max; i++){
			grundy[i] = -1;
		}
		grundy[0] = grundy[1] = grundy[2] = 0;

		BufferedReader br = null;
		File file = new File("input.txt");
		if(file.exists()){
			br = new BufferedReader(new FileReader("input.txt"));
		}
		else{
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		line = br.readLine();
		int N = Integer.parseInt(line);

		int t = grundy(N);
		if(t > 0){
			int ans = getAns(N);
			System.out.println(ans);
		}
		else{
			System.out.println("-1");
		}
	}

	int getAns(int n){

		for(int i = 1; i <= n/2; i++){
			int ret = 0;
			int st = i;
			int sum = 0;
			while(sum < n){
				sum += st;
				st++;
				ret++;
			}
			if(sum == n){
				int gran = 0;
				for(int j = i; j < st; j++){
					gran = gran ^ grundy(j);
				}
				if(gran == 0){
					return ret;
				}
			}
		}

		return 0;
	}

	int grundy(int n){
		if(grundy[n] != -1){
			return grundy[n];
		}
		if(n == 3){
			System.out.print("");
		}
		List<Integer> set = new ArrayList<Integer>();
		for(int i = 1; i <= n/2; i++){
			int st = i;
			int sum = 0;
			while(sum < n){
				sum += st;
				st++;
			}
			if(sum == n){
				int gran = 0;
				for(int j = i; j < st; j++){
					gran = gran ^ grundy(j);
				}
				set.add(gran);
			}
		}

		int g = 0;
		while(set.contains(g)){
			g++;
		}

		grundy[n] = g;
		return g;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		E t = new E();
		t.run();

	}

}

import java.io.*;
import java.util.*;

public class E implements Runnable{

	BufferedReader in;
	StringTokenizer token = null;

	public int nextInt(){
		try{
			while (token==null || !token.hasMoreElements())
					token = new StringTokenizer(in.readLine());
			return Integer.parseInt(token.nextToken());
		} catch (Exception ex){
			ex.printStackTrace(System.err);
			return Integer.MIN_VALUE;
		}
	}

	public String nextWord(){
		try{
			while (token==null || !token.hasMoreElements())
					token = new StringTokenizer(in.readLine());
			return token.nextToken();
		} catch (Exception ex){
			ex.printStackTrace(System.err);
			return null;
		}
	}

	int[] f, a;
	Set<Integer> set = new TreeSet<Integer>();

	@Override
	public void run() {
		try{
			in = new BufferedReader(new InputStreamReader(System.in));
			int n = nextInt();
			f = new int[n + 1];
			a = new int[n + 1];
			f[1] = f[2] = 0;

			for (int i=3; i<=n; ++i){
				int max = -1;
				set.clear();
				for (int k=2; k<i; ++k){
					int sum = k * (k + 1) / 2;
					if (sum > i) break;
					if ((i - sum) % k != 0) continue;
					int left = 1 + (i - sum) / k;
					int right = k + (i - sum) / k;
					int res = 0;
					for (int j=left; j<=right; ++j)
						res = res ^ f[j];
					set.add(res);
					if (res==0 && max==-1) max = k;
				}
				if (max == -1){
					f[i] = 0;
					continue;
				}
				set.add(1000000);
				int res = 0, prev=-1;
				for (Integer x : set){
					if (x != prev + 1){
						res = prev + 1;
					} else prev = x;
				}
				f[i] = res;
				a[i] = max;
			}

			if (f[n]==0)
				System.out.println(-1); else
				System.out.println(a[n]);
			in.close();
		}catch (Exception ex){

		}
	}

	public static void main(String[] args) {
		(new Thread(new E())).start();
	}
}

import java.io.*;
import java.util.*;

public class E implements Runnable{

	BufferedReader in;
	StringTokenizer token = null;

	public int nextInt(){
		try{
			while (token==null || !token.hasMoreElements())
					token = new StringTokenizer(in.readLine());
			return Integer.parseInt(token.nextToken());
		} catch (Exception ex){
			ex.printStackTrace(System.err);
			return Integer.MIN_VALUE;
		}
	}

	public String nextWord(){
		try{
			while (token==null || !token.hasMoreElements())
					token = new StringTokenizer(in.readLine());
			return token.nextToken();
		} catch (Exception ex){
			ex.printStackTrace(System.err);
			return null;
		}
	}

	int[] f, a;
	Set<Integer> set = new TreeSet<Integer>();

	@Override
	public void run() {
		try{
			in = new BufferedReader(new InputStreamReader(System.in));
			int n = nextInt();
			f = new int[n + 1];
			a = new int[n + 1];
			f[1] = f[2] = 0;

			for (int i=3; i<=n; ++i){
				int max = -1;
				set.clear();
				for (int k=2; k<i; ++k){
					int sum = k * (k + 1) / 2;
					if (sum > i) break;
					if ((i - sum) % k != 0) continue;
					int left = 1 + (i - sum) / k;
					int right = k + (i - sum) / k;
					int res = 0;
					for (int j=left; j<=right; ++j)
						res = res ^ f[j];
					set.add(res);
					if (f[res]==0 && max==-1) max = k;
				}
				if (max == -1){
					f[i] = 0;
					continue;
				}
				set.add(1000000);
				int res = 0, prev=-1;
				for (Integer x : set){
					if (x != prev + 1){
						res = prev + 1;
					} else prev = x;
				}
				f[i] = res;
				a[i] = max;
			}

			if (f[n]==0)
				System.out.println(-1); else
				System.out.println(a[n]);
			in.close();
		}catch (Exception ex){

		}
	}

	public static void main(String[] args) {
		(new Thread(new E())).start();
	}
}

import java.io.*;
import java.util.*;

public class E implements Runnable{

	BufferedReader in;
	StringTokenizer token = null;

	public int nextInt(){
		try{
			while (token==null || !token.hasMoreElements())
					token = new StringTokenizer(in.readLine());
			return Integer.parseInt(token.nextToken());
		} catch (Exception ex){
			ex.printStackTrace(System.err);
			return Integer.MIN_VALUE;
		}
	}

	public String nextWord(){
		try{
			while (token==null || !token.hasMoreElements())
					token = new StringTokenizer(in.readLine());
			return token.nextToken();
		} catch (Exception ex){
			ex.printStackTrace(System.err);
			return null;
		}
	}

	int[] f, a;
	Set<Integer> set = new TreeSet<Integer>();

	@Override
	public void run() {
		try{
			in = new BufferedReader(new InputStreamReader(System.in));
			int n = nextInt();
			f = new int[n + 1];
			a = new int[n + 1];
			f[1] = f[2] = 0;

			for (int i=3; i<=n; ++i){
				int max = -1;
				set.clear();
				for (int k=2; k<i; ++k){
					int sum = k * (k + 1) / 2;
					if (sum > i) break;
					if ((i - sum) % k != 0) continue;
					int left = 1 + (i - sum) / k;
					int right = k + (i - sum) / k;
					int res = 0;
					for (int j=left; j<=right; ++j)
						res = res ^ f[j];
					set.add(res);
					if (f[res]==0) max = k;
				}
				if (max == -1){
					f[i] = 0;
					continue;
				}
				set.add(1000000);
				int res = 0, prev=-1;
				for (Integer x : set){
					if (x != prev + 1){
						res = prev + 1;
					} else prev = x;
				}
				f[i] = res;
				a[i] = max;
			}

			if (f[n]==0)
				System.out.println(-1); else
				System.out.println(a[n]);
			in.close();
		}catch (Exception ex){

		}
	}

	public static void main(String[] args) {
		(new Thread(new E())).start();
	}
}

import java.util.*;
import java.math.*;
public class lucksum {

         static long gcd(long a,long b)
         {
                 if(a>b)
                 {
                         return gcd(b,a);
                 }
                 if(a==0)
                         return b;
                 else
                         return gcd(b%a,a);
         }
         public static void main(String[] args)
        {
               Scanner sc=new Scanner(System.in);
               int n=sc.nextInt();
               int dp[]=new int[n+1];
               int res=-1;
               for(int i=3;i<=n;i++)
               {
            	   int con[]=new int[n+1];
            	   for(int j=2;j*(j+1)<=2*i;j++)
            	   {

            			   if(2*i%j!=0)
            				   continue;
            			   if((2*i/j+1-j)%2!=0)
            				   continue;
            			   int t=(2*i/j+1-j)/2;
            			   if(t<=0)
            				   continue;
            			   con[dp[t+j-1]^dp[t-1]]=1;

            			   if((i==n)&&((dp[t+j-1]^dp[t-1])==0))
            			   {
            				   res=j;
            			   }
            	   }
            	   int t=0;
            	   for(int j=0;j<=n;j++)
            	   {
            		   if(con[j]==0)
            		   {
            			   t=j;
            			   break;
            		   }
            	   }
            	   dp[i]=t^dp[i-1];
               }
               System.out.println(res);
               return;
        }

}
class node implements Comparable<node>{
        public int pre;
        public String name;
        /*public node(long v,long addition)
        {
                mv=v;
                maddition=addition;
        }*/
        public int compareTo(node a)
        {
                return this.pre-a.pre;
        }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class C {
    static int[] DP;
    static int[] Sum;

    public static int get(int x) {
        if (DP[x] != 0)
            return DP[x];
        for (int i = 2; Sum[i] <= x; i++) {
            if ((x - Sum[i]) % i == 0) {
                int win = 0;
                for (int j = 0; j < i; j++) {
                    if (get((x - Sum[i]) / i + j + 1) != -1) {
                        win++;
                    }
                }
                if (win % 2 == 0 || (win == 1 && (i - win) % 2 == 0))
                    return DP[x] = i;
            }
        }
        return DP[x] = -1;
    }

    public static void main(String[] args) throws NumberFormatException,
            IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        DP = new int[n + 1];
        Sum = new int[1001];
        for (int i = 1; i < 1001; i++)
            Sum[i] = Sum[i - 1] + i;
        int ans = get(n);
        if (ans > 0)
            System.out.println(ans);
        else
            System.out.println(-1);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class C {
    static int[] DP;
    static int[] Sum;

    public static int get(int x) {
        if (DP[x] != 0)
            return DP[x];
        for (int i = 2; Sum[i] <= x; i++) {
            if ((x - Sum[i]) % i == 0) {
                int win = 0;
                for (int j = 0; j < i; j++) {
                    if (get((x - Sum[i]) / i + j + 1) != -1) {
                        win++;
                    }
                }
                if (win % 2 == 0 || (win%2 == 1 && (i - win) % 2 == 0))
                    return DP[x] = i;
            }
        }
        return DP[x] = -1;
    }

    public static void main(String[] args) throws NumberFormatException,
            IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        DP = new int[n + 1];
        Sum = new int[1001];
        for (int i = 1; i < 1001; i++)
            Sum[i] = Sum[i - 1] + i;
        int ans = get(n);
        if (ans > 0)
            System.out.println(ans);
        else
            System.out.println(-1);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class C {
    static int[] DP;
    static int[] Sum;

    public static int get(int x) {
        if (DP[x] != 0)
            return DP[x];
        for (int i = 2; Sum[i] <= x; i++) {
            if ((x - Sum[i]) % i == 0) {
                int win = 0;
                for (int j = 0; j < i; j++) {
                    if (get((x - Sum[i]) / i + j + 1) != -1) {
                        win++;
                    }
                }
                if (win % 2 == 0 && (i - win) % 2 == 1)
                    return DP[x] = i;
            }
        }
        return DP[x] = -1;
    }

    public static void main(String[] args) throws NumberFormatException,
            IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        DP = new int[n + 1];
        Sum = new int[1001];
        for (int i = 1; i < 1001; i++)
            Sum[i] = Sum[i - 1] + i;
        int ans = get(n);
        if (ans > 0)
            System.out.println(ans);
        else
            System.out.println(-1);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class C {
    static int[] DP;
    static int[] Sum;

    public static int get(int x) {
        if (DP[x] != 0)
            return DP[x];
        for (int i = 2; Sum[i] <= x; i++) {
            if ((x - Sum[i]) % i == 0) {
                int win = 0;
                for (int j = 0; j < i; j++) {
                    if (get((x - Sum[i]) / i + j + 1) != -1) {
                        win++;
                    }
                }
                if (win % 2 == 0 && (i - win) % 2 == 0)
                    return DP[x] = i;
            }
        }
        return DP[x] = -1;
    }

    public static void main(String[] args) throws NumberFormatException,
            IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        DP = new int[n + 1];
        Sum = new int[1001];
        for (int i = 1; i < 1001; i++)
            Sum[i] = Sum[i - 1] + i;
        int ans = get(n);
        if (ans > 0)
            System.out.println(ans);
        else
            System.out.println(-1);
    }
}

import java.io.* ;
import java.util.* ;
import java.math.* ;

public class Main
{
    public static void main( String args[] ) {
        Scanner Input = new Scanner( System.in ) ;
		int SG[] = new int[ 100001 ] ;
		int SUM_SG[] = new int[ 100001 ] ;
		int Ret[] = new int[ 100001 ] ;
		int N = Input.nextInt() ;
		for ( int i = 1 ; i <= N ; i ++ ) {
			boolean H[] = new boolean[ 1001 ] ;
			int M = 2 * i ;
			for ( int k = 2 ; M / k + 1 - k > 0 ; k ++ )
			if ( M % k == 0 && ( M / k + 1 - k ) % 2 == 0 ) {
				int a = ( M / k + 1 - k ) / 2 ;
				int b = a + k - 1 ;
//				System.out.println( i + " " + a + " " + b ) ;
				H[ SG[ b ] ^ SG[ a - 1 ] ] = true ;
				if ( H[ 0 ] && Ret[ i ] == 0 ) {
					Ret[ i ] = k ;
				}
			}
			for ( ; H[ SG[ i ] ] ; SG[ i ] ++ ) ;
			SUM_SG[ i ] = SUM_SG[ i - 1 ] ^ SG[ i ] ;
		}
		if ( Ret[ N ] == 0 ) Ret[ N ] = -1 ;
		System.out.println( Ret[ N ] ) ;
    }
}

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskC {

    int canWin(int n){
        int div = 2;

        while(true){
            if(((long)div * (div - 1)) / 2 >= n) break;

            int x = n - (int)(((long)div * (div - 1)) / 2);

            if(x % div == 0){
                x /= div;
                int cnt = 0;
                for(int start = 0; start < div; start++){
                    if(canWin(x + start) != -1){
                       cnt++;
                    }
                }
                if(cnt % 2 == 0) return div;
            }
            div++;
            continue;
        }

        return -1;
    }

    void run(){
        int n = nextInt();

        int[] res = new int[n + 1];
        Arrays.fill(res, -1);
        int[] grundy = new int[n + 1];

        HashSet<Integer> set = new HashSet<Integer>();
        for(int i = 3; i <= n; i++){
            set.clear();
            for(int div = 2; ((long)div * (div - 1)) / 2 < i; div++){
                int x = i - (int)((long) div * div) / 2;
                if(x % div == 0){
                    int xor = 0;
                    for(int start = 0; start < div; start++)
                        xor ^= grundy[x + start];
                    set.add(xor);
                    if(xor == 0 && res[i] == -1)
                        res[i] = div;
                }
            }
            int r = 0;
            while(set.contains(r))r++;
            grundy[i] = r;
        }

        System.out.println(res[n]);
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new TaskC().run();
    }
}

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 3/26/11
 * Time: 10:53 PM
 * To change this template use File | Settings | File Templates.
 */
public class TaskC {

    int canWin(int n){
        int div = 2;

        while(true){
            if(((long)div * (div - 1)) / 2 >= n) break;

            int x = n - (int)(((long)div * (div - 1)) / 2);

            if(x % div == 0){
                x /= div;
                int cnt = 0;
                for(int start = 0; start < div; start++){
                    if(canWin(x + start) != -1){
                       cnt++;
                    }
                }
                if(cnt % 2 == 0) return div;
            }
            div++;
            continue;
        }

        return -1;
    }

    void run(){
        int n = nextInt();

        int x = canWin(n);
        if(x == -1){
            System.out.println(-1);
        }else{
            System.out.println(x);
        }
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    double nextDouble(){
        return Double.parseDouble(next());
    }

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    public static void main(String[] args){
        new TaskC().run();
    }
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.lang.Double.*;
import static java.math.BigInteger.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable {

	// private long start;

	private void solve() throws IOException {
		// start = System.currentTimeMillis();
		init();
		readData();
		processing();
	}

	private void init() {
	}

	HashSet<Integer> si = new HashSet<Integer>();

	private int mex(List<Integer> lst) {
		si.clear();
		si.addAll(lst);
		int ret = 0;
		while (si.contains(ret)) {
			++ret;
		}
		return ret;
	}

	private void processing() {
		nim = new int[100001];
		nim[0] = 0;
		nim[1] = 0;
		nim[2] = 0;
		nim[3] = 1;
		List<Integer> fg = new ArrayList<Integer>();
		int[] firstTurn = new int[100001];
		firstTurn[3] = 2;
		for (int i = 4; i < 100001; ++i) {
			fg.clear();
			int memo = -1;
			for (int j = 2; j*j <= i; ++j) {
				if (2*i%j == 0) {
					int n = 2*i/j - 1 + j;
					if (n%2 == 0) {
						n /= 2;
						if (n - j + 1 > 0) {
							int xor = 0;
							for (int l = n; l >= n - j + 1; --l) {
								xor ^= nim[l];
							}
							if (xor == 0 && memo == -1) {
								memo = j;
							}
							fg.add(xor);
						}
					}
				}
			}
			nim[i] = mex(fg);
			firstTurn[i] = memo;
		}
		if (nim[nn] == 0) {
			println(-1);
		}
		else {
			println(firstTurn[nn]);
		}
	}

	private void readData() throws IOException {
		nn = nextInt();
	}

	private int nn;

	private int[] nim;

	public static void main(String[] args) throws InterruptedException {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().run();
			}
		}, "1", 1 << 24).start();
	}

	// @Override
	public void run() {
		try {
			boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
			reader = onlineJudge ? new BufferedReader(new InputStreamReader(
					System.in)) : new BufferedReader(
					new FileReader("input.txt"));
			writer = onlineJudge ? new PrintWriter(new BufferedWriter(
					new OutputStreamWriter(System.out))) : new PrintWriter(
					new BufferedWriter(new FileWriter("output.txt")));
			Locale.setDefault(Locale.US);
			tokenizer = null;
			solve();
			writer.flush();
		} catch (Exception error) {
			error.printStackTrace();
			System.exit(1);
		}
	}

	class InputReader {

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		private InputStream stream;
		private byte[] buf = new byte[1 << 16];
		private int curChar;
		private int numChars;
	}

	private class Parser {

		public Parser(InputStream in) {
			din = new DataInputStream(in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public byte c;

		public int nextInt() throws IOException {
			int value = 0;
			c = read();
			while (c <= ' ')
				c = read();
			boolean neg = c == '-';
			if (neg)
				c = read();
			do {
				value = value * 10 + c - 48;
				c = read();
			} while (c > ' ');
			if (neg) {
				return -value;
			} else {
				return value;
			}
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		public byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		final private int BUFFER_SIZE = 1 << 16;
	}

	private BufferedReader reader;
	private PrintWriter writer;
	private StringTokenizer tokenizer;

	private void println() {
		writer.println();
	}

	private void print(Object obj) {
		writer.print(obj);
	}

	private void println(Object obj) {
		writer.println(obj);
	}

	private void printf(String f, Object... obj) {
		writer.printf(f, obj);
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.lang.Double.*;
import static java.math.BigInteger.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable {

	// private long start;

	private void solve() throws IOException {
		// start = System.currentTimeMillis();
		init();
		readData();
		processing();
	}

	private void init() {
	}

	HashSet<Integer> si = new HashSet<Integer>();

	private int mex(List<Integer> lst) {
		si.clear();
		si.addAll(lst);
		int ret = 0;
		while (si.contains(ret)) {
			++ret;
		}
		return ret;
	}

	private void processing() {
		nim = new int[100001];
		nim[0] = 0;
		nim[1] = 0;
		nim[2] = 0;
		nim[3] = 1;
		List<Integer> fg = new ArrayList<Integer>();
		int[] firstTurn = new int[100001];
		firstTurn[3] = 2;
		for (int i = 4; i < 100001; ++i) {
			fg.clear();
			int memo = -1;
			for (int j = 2; j*j < i; ++j) {
				if (2*i%j == 0) {
					int n = 2*i/j - 1 + j;
					if (n%2 == 0) {
						n /= 2;
						if (n - j + 1 > 0) {
							int xor = 0;
							for (int l = n; l >= n - j + 1; --l) {
								xor ^= nim[l];
							}
							if (xor == 0 && memo == -1) {
								memo = j;
							}
							fg.add(xor);
						}
					}
				}
			}
			nim[i] = mex(fg);
			firstTurn[i] = memo;
		}
		if (nim[nn] == 0) {
			println(-1);
		}
		else {
			println(firstTurn[nn]);
		}
	}

	private void readData() throws IOException {
		nn = nextInt();
	}

	private int nn;

	private int[] nim;

	public static void main(String[] args) throws InterruptedException {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().run();
			}
		}, "1", 1 << 24).start();
	}

	// @Override
	public void run() {
		try {
			boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
			reader = onlineJudge ? new BufferedReader(new InputStreamReader(
					System.in)) : new BufferedReader(
					new FileReader("input.txt"));
			writer = onlineJudge ? new PrintWriter(new BufferedWriter(
					new OutputStreamWriter(System.out))) : new PrintWriter(
					new BufferedWriter(new FileWriter("output.txt")));
			Locale.setDefault(Locale.US);
			tokenizer = null;
			solve();
			writer.flush();
		} catch (Exception error) {
			error.printStackTrace();
			System.exit(1);
		}
	}

	class InputReader {

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		private InputStream stream;
		private byte[] buf = new byte[1 << 16];
		private int curChar;
		private int numChars;
	}

	private class Parser {

		public Parser(InputStream in) {
			din = new DataInputStream(in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public byte c;

		public int nextInt() throws IOException {
			int value = 0;
			c = read();
			while (c <= ' ')
				c = read();
			boolean neg = c == '-';
			if (neg)
				c = read();
			do {
				value = value * 10 + c - 48;
				c = read();
			} while (c > ' ');
			if (neg) {
				return -value;
			} else {
				return value;
			}
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		public byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		final private int BUFFER_SIZE = 1 << 16;
	}

	private BufferedReader reader;
	private PrintWriter writer;
	private StringTokenizer tokenizer;

	private void println() {
		writer.println();
	}

	private void print(Object obj) {
		writer.print(obj);
	}

	private void println(Object obj) {
		writer.println(obj);
	}

	private void printf(String f, Object... obj) {
		writer.printf(f, obj);
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.lang.Double.*;
import static java.math.BigInteger.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable {

	// private long start;

	private void solve() throws IOException {
		// start = System.currentTimeMillis();
		init();
		readData();
		processing();
	}

	private void init() {
	}

	HashSet<Integer> si = new HashSet<Integer>();

	private int mex(List<Integer> lst) {
		si.clear();
		si.addAll(lst);
		int ret = 0;
		while (si.contains(ret)) {
			++ret;
		}
		return ret;
	}

	private void processing() {
		nim = new int[100001];
		nim[0] = 0;
		nim[1] = 0;
		nim[2] = 0;
		nim[3] = 1;
		List<Integer> fg = new ArrayList<Integer>();
		int[] firstTurn = new int[100001];
		for (int i = 4; i < 100001; ++i) {
			fg.clear();
			int memo = -1;
			for (int j = 2; j*j < i; ++j) {
				if (2*i%j == 0) {
					int n = 2*i/j - 1 + j;
					if (n%2 == 0) {
						n /= 2;
						int xor = 0;
						for (int l = n; l >= n - j + 1; --l) {
							xor ^= nim[l];
						}
						if (xor == 0 && memo == -1) {
							memo = j;
						}
						fg.add(xor);
					}
				}
			}
			nim[i] = mex(fg);
			firstTurn[i] = memo;
		}
		if (nim[nn] == 0) {
			println(-1);
		}
		else {
			println(firstTurn[nn]);
		}
	}

	private void readData() throws IOException {
		nn = nextInt();
	}

	private int nn;

	private int[] nim;

	public static void main(String[] args) throws InterruptedException {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().run();
			}
		}, "1", 1 << 24).start();
	}

	// @Override
	public void run() {
		try {
			boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
			reader = onlineJudge ? new BufferedReader(new InputStreamReader(
					System.in)) : new BufferedReader(
					new FileReader("input.txt"));
			writer = onlineJudge ? new PrintWriter(new BufferedWriter(
					new OutputStreamWriter(System.out))) : new PrintWriter(
					new BufferedWriter(new FileWriter("output.txt")));
			Locale.setDefault(Locale.US);
			tokenizer = null;
			solve();
			writer.flush();
		} catch (Exception error) {
			error.printStackTrace();
			System.exit(1);
		}
	}

	class InputReader {

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		private InputStream stream;
		private byte[] buf = new byte[1 << 16];
		private int curChar;
		private int numChars;
	}

	private class Parser {

		public Parser(InputStream in) {
			din = new DataInputStream(in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public byte c;

		public int nextInt() throws IOException {
			int value = 0;
			c = read();
			while (c <= ' ')
				c = read();
			boolean neg = c == '-';
			if (neg)
				c = read();
			do {
				value = value * 10 + c - 48;
				c = read();
			} while (c > ' ');
			if (neg) {
				return -value;
			} else {
				return value;
			}
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		public byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		final private int BUFFER_SIZE = 1 << 16;
	}

	private BufferedReader reader;
	private PrintWriter writer;
	private StringTokenizer tokenizer;

	private void println() {
		writer.println();
	}

	private void print(Object obj) {
		writer.print(obj);
	}

	private void println(Object obj) {
		writer.println(obj);
	}

	private void printf(String f, Object... obj) {
		writer.printf(f, obj);
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.lang.Double.*;
import static java.math.BigInteger.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main implements Runnable {

	// private long start;

	private void solve() throws IOException {
		// start = System.currentTimeMillis();
		init();
		readData();
		processing();
	}

	private void init() {
	}

	HashSet<Integer> si = new HashSet<Integer>();

	private int mex(List<Integer> lst) {
		si.clear();
		si.addAll(lst);
		int ret = 0;
		while (si.contains(ret)) {
			++ret;
		}
		return ret;
	}

	private void processing() {
		nim = new int[100001];
		nim[0] = 0;
		nim[1] = 0;
		nim[2] = 0;
		nim[3] = 1;
		List<Integer> fg = new ArrayList<Integer>();
		int[] firstTurn = new int[100001];
		firstTurn[3] = 2;
		for (int i = 4; i < 100001; ++i) {
			fg.clear();
			int memo = -1;
			for (int j = 2; j*j < i; ++j) {
				if (2*i%j == 0) {
					int n = 2*i/j - 1 + j;
					if (n%2 == 0) {
						n /= 2;
						int xor = 0;
						for (int l = n; l >= n - j + 1; --l) {
							xor ^= nim[l];
						}
						if (xor == 0 && memo == -1) {
							memo = j;
						}
						fg.add(xor);
					}
				}
			}
			nim[i] = mex(fg);
			firstTurn[i] = memo;
		}
		if (nim[nn] == 0) {
			println(-1);
		}
		else {
			println(firstTurn[nn]);
		}
	}

	private void readData() throws IOException {
		nn = nextInt();
	}

	private int nn;

	private int[] nim;

	public static void main(String[] args) throws InterruptedException {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().run();
			}
		}, "1", 1 << 24).start();
	}

	// @Override
	public void run() {
		try {
			boolean onlineJudge = System.getProperty("ONLINE_JUDGE") != null;
			reader = onlineJudge ? new BufferedReader(new InputStreamReader(
					System.in)) : new BufferedReader(
					new FileReader("input.txt"));
			writer = onlineJudge ? new PrintWriter(new BufferedWriter(
					new OutputStreamWriter(System.out))) : new PrintWriter(
					new BufferedWriter(new FileWriter("output.txt")));
			Locale.setDefault(Locale.US);
			tokenizer = null;
			solve();
			writer.flush();
		} catch (Exception error) {
			error.printStackTrace();
			System.exit(1);
		}
	}

	class InputReader {

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int readInt() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long readLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private String readLine0() {
			StringBuffer buf = new StringBuffer();
			int c = read();
			while (c != '\n' && c != -1) {
				if (c != '\r')
					buf.appendCodePoint(c);
				c = read();
			}
			return buf.toString();
		}

		public String readLine() {
			String s = readLine0();
			while (s.trim().length() == 0)
				s = readLine0();
			return s;
		}

		public String readLine(boolean ignoreEmptyLines) {
			if (ignoreEmptyLines)
				return readLine();
			else
				return readLine0();
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public double readDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, readInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		private InputStream stream;
		private byte[] buf = new byte[1 << 16];
		private int curChar;
		private int numChars;
	}

	private class Parser {

		public Parser(InputStream in) {
			din = new DataInputStream(in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public byte c;

		public int nextInt() throws IOException {
			int value = 0;
			c = read();
			while (c <= ' ')
				c = read();
			boolean neg = c == '-';
			if (neg)
				c = read();
			do {
				value = value * 10 + c - 48;
				c = read();
			} while (c > ' ');
			if (neg) {
				return -value;
			} else {
				return value;
			}
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		public byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		final private int BUFFER_SIZE = 1 << 16;
	}

	private BufferedReader reader;
	private PrintWriter writer;
	private StringTokenizer tokenizer;

	private void println() {
		writer.println();
	}

	private void print(Object obj) {
		writer.print(obj);
	}

	private void println(Object obj) {
		writer.println(obj);
	}

	private void printf(String f, Object... obj) {
		writer.printf(f, obj);
	}

	private int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * Author -
 * User: kansal
 * Date: 6/7/11
 * Time: 11:55 PM
 */
public class Game {
    public static void main(String[] args) {
        reader = new BufferedReader(new InputStreamReader(System.in));

        int n = nextInt();
        int[] sum = new int[501];
        for(int i = 1; i <= 500; ++i) {
            sum[i] = i + sum[i-1];
            if (sum[i] >= 100000) {
                sum[i] = 100500;
            }
        }

        int[] f = new int[n+1];
        f[1] = -1;
        f[2] = -2;
        int res = -1;
        for(int i = 3; i <= n; ++i) {
            f[i] = f[i-1] - 1;
            for(int j = 1; sum[j] < i; ++j) {
                if ((i - sum[j]) % (j + 1) == 0) {
                    int x = (i - sum[j]) / (j + 1);
                    if (Math.abs(f[x-1] - f[x + j]) % 2 == 0) {
                        if (i == n) {
                            res = j+1;
                        }
                        f[i] += 2;
                        break;
                    }
                }
            }
        }

        System.out.println(res);
    }

    public static BufferedReader reader;

    public static StringTokenizer tokenizer = null;

    static String nextToken() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    static public int nextInt() {
        return Integer.parseInt(nextToken());
    }

    static public String next() {
        return nextToken();
    }

    static public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}

import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;

public class Contest73_3 {
    public static int []gr;
    public static LinkedList<Point> getNums(int num){
        LinkedList<Point> res = new LinkedList<Point>();
        for (int i = 2; (i*(i+1)/2)<=num; i++) {
            int rem = num-(i*(i+1)/2);
            if(rem%i==0){
                int st = (rem/i) + 1;
                int en = st+i-1;
                res.add(new Point(st,en));
            }
        }
        return res;
    }
    public static int grundy(int n){
        if(n==0 || n==1 || n==2)
            return 0;
        if(gr[n]!=-1)
           return gr[n];
        LinkedList<Point> curr = getNums(n);
        HashSet<Integer> s = new HashSet<Integer>();
        for (Point i : curr) {
            int st = i.x;
            int en = i.y;
            int xor = 0;
            for (int j = st; j <= en; j++) {
                xor = xor ^ grundy(j);
            }
            s.add(xor);
        }
        for (int i = 0;; i++) {
            if(!s.contains(i))
                return gr[n] = i;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        gr = new int [n+1];
        Arrays.fill(gr,-1);
        grundy(n);
        int res = -1;
        LinkedList<Point> curr = getNums(n);
        HashSet<Integer> s = new HashSet<Integer>();
        for (Point i : curr) {
            int st = i.x;
            int en = i.y;
            int x = 0;
            for (int j = st; j <= en; j++) {
               // if(st==9)
               //   System.out.println(x);
                x = x ^ gr[j];
            }
            if(x==0)
                res = en-st+1;
        }
        System.out.println(res);
    }
}