n = gets.chomp.to_i
i = 1

judge = []

while true do
  if n == i
    break
  elsif n % i == 0
    set = []
    set.push(i, n/i)
    judge.push(set)
  end
  i += 1
end

count = []
judge.each do |value|
  count.push((value[0]-1) + (value[1]-1))
end

p count.sort[0]