N = gets.to_i
if N == 1 then
    puts '0'
    exit
end
result = []
num = N
i = 2
while i <= Math.sqrt(num) do
    if num % i == 0
        result << i
    end
    i += 1
end
min = N*2
result.each do |a|
    b = N/a
    dist = a+b-2
    min = dist if min > dist
end
puts min