require 'prime'
N = gets.to_i
if N == 1 then
    puts '0'
    exit
end
D = N.prime_division
array = []
D.each do |d|
    d[1].times do |i|
        array.push d[0]**(i+1)
    end
end
min = 10**12
array.each do |a|
    b = N/a
    dist = a+b-2
    min = dist if min > dist
end
puts min