n=int(eval(input()))

divisors = []

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

    if n % i == 0:

        divisors.append(i)

        if i != n // i:

            divisors.append(n//i)

if n==divisors[-1]**2:

    print((divisors[-1]*2-2))

else:

    print((divisors[-1]+divisors[-2]-2))
n=int(eval(input()))

divisors = []

def a(n):

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

        if n % i == 0:

            divisors.append(i)

            divisors.append(n//i)

    divisors.sort()

    return divisors

a(n)

x=len(divisors)//2

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

n = int(eval(input()))
divisors = []


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


a(n)
x = len(divisors) // 2
print((divisors[x] + divisors[x - 1] - 2))

-for i in range(1, int(n**0.5) + 1): -    if n % i == 0: -        divisors.append(i) -        if i != n // i: + + +def a(n): +    for i in range(1, int(n**0.5) + 1): +        if n % i == 0: +            divisors.append(i) -if n == divisors[-1] ** 2: -    print((divisors[-1] * 2 - 2)) -else: -    print((divisors[-1] + divisors[-2] - 2)) +    divisors.sort() +    return divisors + + +a(n) +x = len(divisors) // 2 +print((divisors[x] + divisors[x - 1] - 2))