n = gets.chomp.to_i
a = 0
b = 0
c = 1
d = []
i = 0
s = [] 
ans = 0
while true
  i += 1
  c = 1
  b = n / i
  c = n % i
  if c == 0
    s << b
    d << i
  end
  break if b == 0
end
s.reverse!
d.reverse!
if s.length > 2
  ans = (s[2]- 1 )+ (d[2]- 1)
else
  ans = (s[0]- 1 )+ (d[0]- 1)
end
puts ans