 
n=gets.to_i
 
s=10000000000000
a=[]
 flag=0
(1..n**0.5).each do |m|
    if n%m==0
        v=n.div(m)
        if (v-1)+(m-1)<s
            s=(v-1)+(m-1)
       flag=1
        end
        
    end
    next
end
 
if flag==0
p n-1
else
p s
end