require 'pp'
require 'prime'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    n = gets.chomp.to_i

    # 素因数分解
    primes = Prime.prime_division(n)  #=> [[5, 1], [197, 1], [461, 1]]
    puts primes

    # 再帰総当り
    min_step = 1000000000000
    primes.each do |(p, cnt)|
      cur = 1
      0.upto(cnt) do |i|
        d = n / cur

        step = (cur - 1) + (d - 1)
        if step < min_step
          min_step = step
        end

        cur *= p
      end
    end

    puts min_step
  end
end

if __FILE__ == $0
  Solver.new.main
end
