n = gets.chomp.to_i

def factor(num)
  result = []
  i = 2
  while i <= num do
    if num % i == 0
      result << i
      num = num / i
    else
      i += 1
    end
  end
  return result
end

ans = []
factor(n).uniq.each do |i|
  s, a = n.divmod(i)
  if a == 0
    ans.push(s-1 + i-1)
  end
end
p ans.min
