#include <iostream>
#include <cmath>
using namespace std;
long long max_number(long long n1, long long n0)
{
long long number;
for (int i=n0+n1-1;i>=n0;i--)
{
number+=pow(2,i);
}
return(number);
}
long long min_number(long long n1, long long n0)
{
long long number;
for (int i=n1-1;i>=0;i--)
{
number+=pow(2,i);
}
return(number);
}
int main()
{
long long n;
cin>>n;
long long n1=0;
long long n0=0;
while (n>0)
{
if (n%2==1) n1++;
else n0++;
n/=2;
}
cout<<max_number(n1,n0)-min_number (n1,n0);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpsb25nIGxvbmcgbWF4X251bWJlcihsb25nIGxvbmcgbjEsIGxvbmcgbG9uZyBuMCkKewoJbG9uZyBsb25nICBudW1iZXI7Cglmb3IgKGludCBpPW4wK24xLTE7aT49bjA7aS0tKQoJewoJCW51bWJlcis9cG93KDIsaSk7CQoJfQoJcmV0dXJuKG51bWJlcik7Cn0KCmxvbmcgbG9uZyBtaW5fbnVtYmVyKGxvbmcgbG9uZyBuMSwgbG9uZyBsb25nIG4wKQp7Cglsb25nIGxvbmcgIG51bWJlcjsKCWZvciAoaW50IGk9bjEtMTtpPj0wO2ktLSkKCXsKCQludW1iZXIrPXBvdygyLGkpOwkKCX0KCXJldHVybihudW1iZXIpOwp9CgppbnQgbWFpbigpIAp7Cglsb25nIGxvbmcgbjsKCWNpbj4+bjsKCWxvbmcgbG9uZyBuMT0wOwoJbG9uZyBsb25nIG4wPTA7Cgl3aGlsZSAobj4wKQoJewoJCWlmIChuJTI9PTEpIG4xKys7CgkJZWxzZSBuMCsrOwoJCW4vPTI7Cgl9CgkKCWNvdXQ8PG1heF9udW1iZXIobjEsbjApLW1pbl9udW1iZXIgKG4xLG4wKTsKCXJldHVybiAwOwp9