program walk_on_multiplication_table
    implicit none
    integer(8):: n
    integer(8)::a,b, i
    read*, n

    do i=1, nint(sqrt(dble(n)))
        if (mod(n,i) == 0) then
            a = i
            b = n/i
        end if
    end do

    print*, a+b-2

end program walk_on_multiplication_table