n = int(eval(input()))



t = []

for i in range(1, int(n**0.5+1)):

   if n % i == 0:

      t.append(int(i+n/i))



print((min(t) - 2))

def make_divisors(n):

   divisors = []

   for i in range(1, int(n**0.5)+1):

      if n % i == 0:

         divisors.append([i, n // i])



   return divisors





n = int(eval(input()))



divisors = make_divisors(n)

print((min([sum(x)-2 for x in divisors])))

n = int(eval(input()))
t = []
for i in range(1, int(n**0.5 + 1)):
    if n % i == 0:
        t.append(int(i + n / i))
print((min(t) - 2))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append([i, n // i])
    return divisors


n = int(eval(input()))
divisors = make_divisors(n)
print((min([sum(x) - 2 for x in divisors])))

+def make_divisors(n): +    divisors = [] +    for i in range(1, int(n**0.5) + 1): +        if n % i == 0: +            divisors.append([i, n // i]) +    return divisors + + -t = [] -for i in range(1, int(n**0.5 + 1)): -    if n % i == 0: -        t.append(int(i + n / i)) -print((min(t) - 2)) +divisors = make_divisors(n) +print((min([sum(x) - 2 for x in divisors])))