var i,j,k:longint;beginwhile not eof do beginreadln(i,j);k:=0;repeatk:=k+i;i:=i div j;until i=0;writeln(k);end;end.