var
x,y:array[0..100] of integer;
i,j,k,m,n,v,ans,l:longint;
begin
assign(input,'bita.in');
assign(output,'bita.out');
reset(input);
rewrite(output);
read(n);
m:=n;
while m<>0 do begin i:=i+1; x[i]:=m mod 2; m:=m div 2; end;
v:=i;
i:=0;
y[v+1]:=1;
for i:=v-1 downto 1 do
begin
for j:=1 to v do y[j]:=x[j];
if (y[i]=0)or(y[i+1]=0) then
begin
k:=i+2;
while y[k]=0 do k:=k+1;
y[k]:=0;
for j:=k-1 downto 1 do y[j]:=1;
end;
if k<=v then
begin
k:=0; m:=1; l:=0;
while l<>v do
begin
l:=l+1;
if (l<>i)and(l<>i+1) then begin ans:=ans+y[l]*m; m:=m*2; end;
end;
ans:=ans+1;
end;
end;
writeln(ans);
close(input);
close(output);
end.