require 'prime'
N = gets.to_i
if N == 1 then
    puts '0'
    exit
end
D = N.prime_division
q = []
array = []
D.each do |d|
    q.push d[0]
    d[1].times do |i|
        array.push d[0]
    end
end
array.combination(2).to_a.each_with_index do |z, index|
    q.push z[0]*z[1] unless q.include?(z[0]*z[1])
end
min = N*2
q.each do |a|
    b = N/a
    dist = a+b-2
    min = dist if min > dist
end
puts min