require 'prime'

n = gets.chomp.to_i

factors = n.prime_division
if factors.size == 1
  puts n-1
  exit
end

x, y = 1, 1
dir = 1
while x * y < n
  if dir == 1
    x += 1
    if n % x == 0 
      dir *= -1
      break if x * y == n
      y = x + 1
    end
  else
    y += 1
    if n % y == 0 
      dir *= -1
      break if x * y == n
      x = y + 1
    end
  end
end

puts x + y - 2
