n = int(eval(input()))

def is_prime(num):

    import math

    if num == 2:

        return True

    elif num <  3 or num % 2 == 0:

        return False

    for i in range(3, int(math.sqrt(num)) + 1, 2):

        if num % i == 0:

            return False

    return True



if is_prime(n):

    print((n-1))

    exit()



ans = float('inf')

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

    if n%i == 0:

        ans = min(ans, (i-1)+(n//i-1))

print(ans)
n = int(eval(input()))

ans = float('inf')

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

    if n%i == 0:

        ans = min(ans, (i-1)+(n//i-1))

print(ans)
n = int(eval(input()))


def is_prime(num):
    import math

    if num == 2:
        return True
    elif num < 3 or num % 2 == 0:
        return False
    for i in range(3, int(math.sqrt(num)) + 1, 2):
        if num % i == 0:
            return False
    return True


if is_prime(n):
    print((n - 1))
    exit()
ans = float("inf")
for i in range(int(n**0.5), 0, -1):
    if n % i == 0:
        ans = min(ans, (i - 1) + (n // i - 1))
print(ans)

n = int(eval(input()))
ans = float("inf")
for i in range(int(n**0.5), 0, -1):
    if n % i == 0:
        ans = min(ans, (i - 1) + (n // i - 1))
print(ans)

- - -def is_prime(num): -    import math - -    if num == 2: -        return True -    elif num < 3 or num % 2 == 0: -        return False -    for i in range(3, int(math.sqrt(num)) + 1, 2): -        if num % i == 0: -            return False -    return True - - -if is_prime(n): -    print((n - 1)) -    exit()