文件目录

#include <bits/stdc++.h>
using namespace std;
int n;
int getone(int num)
{
    int ans = 0;
    while (num)
    {
        if (num % 2)
            ans++;
        num /= 2;
    }
    return ans;
}
int main()
{
    while (cin >> n)
    {
        if (n == 0)
            break;
        int a = getone(n);
        for (int i = n + 1; i <= 1000000; i++)
            if (a == getone(i))
            {
                cout << i << endl;
                break;
            }
    }
    return 0;
}