require 'prime'


n=gets.to_i
if Prime.prime?(n)
    puts n-1
    exit
end

s=10000000000000
a=[]

(1..n).each do |m|
    if n%m==0
        v=n.div(m)
        if (v-1)+(m-1)<s
            s=(v-1)+(m-1)
        end
        
    end
    next
end

p s