X = gets.to_i (X - 2 ** 18).upto(X + 2 ** 18) do |n| next if n <= 0 m = n.to_s(2).count('1') x = n ^ m if x == X puts n exit end end puts -1