N = int(input()) player = 1 kaisu =1 for i in range(1,N*2): nishin = list(bin(player)) del nishin[0:2] nN=nishin.count("1") if nN<=N-player: player+=nN kaisu+=1 if N==player: print(kaisu) break else: player-=nN kaisu +=1 if N!=player: print(-1)