program main 
 implicit none
 integer*8 N,i,j,tmp
 read(*,*) N
 tmp = N - 1
 j = N/2
 do i=1,N/2
  if(mod(N,i)==0) then
   if(i-1+N/i-1 < tmp) then
    tmp = i-1+N/i-1
   end if
  end if
  j = min(j,N/i+1)
  if(j < i) exit
 end do
 write(*,*) tmp
end program main
  