program Project2; {$APPTYPE CONSOLE} const k = 30; var i:byte; len:integer; a:array[0..k] of byte; n:integer; max:longint; f:text; procedure dec2bin; var i,buf:byte; begin i:=0; len:=-1; while (n>0) do begin a[i]:=n mod 2; n:=n div 2; len:=len+1; i:=i+1; end; end; procedure bin2dec; var i,j:byte; sum:longint; begin n:=0; if (a[0]=1) then n:=1; for i:=1 to len do begin sum:=0; if (a[i]=1) then begin sum:=2; for j:=2 to i do sum:=sum*2; end; n:=n+sum; end; end; procedure zsuv; var i,buf:byte; begin buf:=a[0]; for i:=1 to len do a[i-1]:=a[i]; a[len]:=buf; end; begin assign(f,'binary.dat'); reset(f); readln(f,n); close(f); max:=n; dec2bin; if (len>0) then begin for i:=1 to len do begin zsuv; bin2dec; if (n>max) then max:=n; end; end; assign(f,'binary.sol'); rewrite(f); writeln(f,max); close(f); end.