ifi = open("DATA3.txt", "r")
ofi = open ("OUT3.txt", "w")

def count(num):
    num = list(bin(num))
    num = "".join(num[2:])

    weight = num.count("1")
    return weight
    
for case in range(5):
    line = int(ifi.readline())

    weight1 = count(line)

    ans = 0
    weight2 = 0
    ans = line
    while weight2 != weight1:
        ans += 1
        weight2 = count(ans)

        
    ofi.write(str(ans) + "\n")

ofi.close()

