require "prime"
n=gets.to_i
if Prime.prime?(n)
  puts n-1
else
  max=1
  min=1
  for i in 2..n
    if (n%i).zero?
      if i>n/i
        break
      end
      max=i
      min=n/i
    end 
  end
  puts (max-1)+(min-1)
end
