
#include<iostream>
#include<string>
#include<cmath>
#include<fstream>
#include<string>
#include<sstream>

using namespace std ;

string binary(int n) {
	string result;
	for (int i = 8*(sizeof(int))-1; i >= 0; --i) {
		if (n & (int)pow(2, i) ) result+="1";
		else result+="0";
	}
	return result;
}

int onecount(int n)  {
	int count = 0;
	for (int i = 8*(sizeof(int))-1; i >= 0; --i) {
		if (n & (int)pow(2, i) ) count+=1;
	}
	return count;
}



int main ()
{
	ifstream in("DATA3.txt");
	ofstream out("OUT3.txt");

    string line;
	stringstream ss;
	while (getline(in, line) ) {
        ss.str(line);
        int n = 0;
        ss >> n;
        ss.clear();

        int o = n+1;
        while (onecount(o) != onecount(n) ) {
            o++;
        }

    out << o << endl;


	}

	return 0; // return all of the 0s
}

