
def my_soinsu_bunkai(n)
  arr=[]
  arr<<1
  i = 2

  while (i*i)<=n
    #puts "now n = #{n}, arr = #{arr}"
    if n%i==0
      arr<<i
      while n%i==0 do
        n/=i
      end
    else
      i+=1
    end
  end
  #puts i
  #puts n 
  if n!=1
    arr<<n
  end
  return arr
end

n = gets.chomp.to_i

#pp my_soinsu_bunkai(n)


arr = my_soinsu_bunkai(n)
puts ((arr[arr.length-1]-1) + ( n / arr[arr.length-1] )-1)