var
n,i,j,m,k,x,y,z,l:longint;
s:array[0..1000000]of integer;
begin
assign(input,'bita.in');
assign(output,'bita.out');
reset(input);
rewrite(output);
read(n);
for i:=1 to n do
begin
z:=0;
while s[z]=1 do
begin
s[z]:=0;
z:=z+1;
if z>m then m:=z;
end;
s[z]:=1;
for j:=0 to m+1 do
begin
if s[j]=1 then x:=x+1
else if x>0 then begin y:=y+x-1; x:=0; end;
end;
end;
write(y);
close(input); close(output);
end.