program ABC144C
    implicit none
    integer(8)::N,i,result

    read*,N

    do i=1,int(sqrt(real(N)))
        if(i==1) then
            result=N-1
        else if(mod(N,i)==0.and.N/i+i-2<result) then
            result=N/i+i-2
        end if
    end do

    print'(i0)',result
    
end program ABC144C