import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();

        for (long y = 1; y <= (long) 1e6; y++) { // 为了效率，只枚举到1e6，一般足够找出最小的y
            long z = x ^ y;
            if (z == 0) continue;
            if (x % z == 0 && y % z == 0) {
                System.out.println(y);
                return;
            }
        }

        System.out.println(-1);
    }
}
