program Y042B
    implicit none
    integer(8)::N,ans,Ns,i
    read*,N
    Ns=int(sqrt(real(N)))
    do i=1,Ns+1
        if(i==1)then
            ans=N-1
        else if(mod(N,i)==0)then
            ans=min(ans,i+N/i-2)
        end if
    end do

    print'(i0)',ans
end program Y042B