N = gets.to_i
count = 0
combs = []
min = []
(1..N).each do |n|
  r = []
  a = N / n if N % n === 0
  b = N / a if a && N % a === 0
  if a && b
	r[0] = a
  	r[1] = b
    combs << r
  end
end
combs.each do |c|
  cur = (c[0] - 1) + (c[1] - 1)
  count = cur unless count != 0 && cur > count
end
p count