#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int

require 'prime'

def divisor(n)
  division_elems = Prime.prime_division(n).each_with_object([]) do |(prime, multi), sum|
    multi.times { sum.push(prime) }
  end
  set = Set.new
  ans = SortedSet.new
  ans.add(1); ans.add(n)
  arr = [*0...division_elems.length]
  [*1...division_elems.length].each do |i|
    arr.combination(i) do |a|
      division_arr = a.map { division_elems[_1] }
      next if set.include?(division_arr)
      set.add(division_arr)
      ans.add division_arr.reduce(1) { |prev, cur| prev * cur }
    end
  end
  ans.to_a
end

ans = N - 1
divisor(N).each do |x|
  y = N / x
  res = x - 1 + y - 1
  ans = res if res < ans
end

puts ans


