N = gets.to_i

require 'prime'

if N.prime?
  puts N - 1
else
  dl = ->(n){n.prime_division.map{|p, k| (0 .. k).map{|i| p**i}}.inject(&:product).map{|a, b| a*b}.sort}
  x = dl[N].bsearch{|v| v >= Math.sqrt(N)}
  puts (x - 1) + (N/x - 1)
end