#include<fstream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
	ifstream f1("BAI4_17.INP");
	ofstream f2("BAI4_17.OUT");
	int n;
	f1>>n;
	string s;
	int i;
	i=0;
	int j=0;
	while(n!=0)
	{
		if (n%2 == 1) s = "1" + s;
		else s = "0" + s;
		n/=2;
		j++;
	}
	int d=0;
	f2 << s << endl;
	string s1 = s;
	while (d != s.length())
        {
          ++d;
          s = s[s.length()-1] + s;
          s.erase(s.length()-1,1);
          if (s1 < s) s1 = s;
         }
    long long tg = 1,u = 0;
    for (int i = s.length()-1; i >= 0; --i)
    {
        if (s1[i] == 49) u += tg;
        tg *= 2;
    }
    f2 << u;
	f1.close();
	f2.close();
	return 0;
}
