X = int(input()) binx = bin(X)[2:] Wmax = len(binx) flag = -1 for w in range(1,Wmax+1): N = X^w binN = bin(N)[2:] c = binN.count("1") if c==w: flag = N break print(flag)