require 'prime'

a = gets.to_i

pr = []
prime = Prime.each(Math.sqrt(a).to_i+1).to_a
prime.each do |e|
  while a % e == 0
    pr << e
    a = a / e
  end
end
if a > 1
  pr << a
end

#p pr

i,j = 1,1

pr.reverse_each do |k|
  if i < j
    i *= k
  else
    j *= k
  end
end

#p i
#p j
ans = i+j-2
print("#{ans}")