#include<bits/stdc++.h>

using namespace std;

int demSCS(int n)
{
	int dem =0;
	if(n==0) return 1;
	while(n>0)
	{
		n=n/10;
		dem++;
	}
	return dem;
}

int heNhiPhan(int n)
{

	int dem = 0;
	int tong = 0;
	int sdu=0;
	while(n>0)
	{
		sdu=n%2;
		tong+= sdu * pow(10, dem);
		n=n/2;
		dem++;
	}
	return tong;
	
}
void pushNumberToArray(int a[], int n)
{
	int dem =0;
	while(n > 0)
	{
		a[dem] = n%10;
		dem++;
		n= n/10;
	}
}
int binaryToDecima (int a[], int dem)
{
	int ret =0;
	for(int i = dem - 1 ; i >= 0; i-- )
	{
		ret += a[i] * pow(2,i);
	} 
	return ret;
}
int soLonNhat(int a[], int dem)
{
	int ret = 0;
	sort(a, a+ dem);
	ret= binaryToDecima(a,dem);
	return ret;		
}
int main()
{
	int n;
	ifstream f1("BAI4_17.INP");
	ofstream f2("BAI4_17.OUT");
	f1>>n;
	int a[1000];
	int tong= heNhiPhan(n);
	int dem = demSCS(tong);
	pushNumberToArray(a, tong);
	int ret= soLonNhat(a,dem);
	f2<<tong<<endl<<ret;
}
