import math





def is_prime(q):

    q = abs(q)

    if q == 2: return True

    if q < 2 or q & 1 == 0: return False

    return pow(2, q - 1, q) == 1





def main(n):

    if is_prime(n):

        return n - 1

    else:

        sqrt = int(math.sqrt(n))

        for i in range(sqrt, 1, -1):

            div, mod = divmod(n, i)

            if mod == 0:

                return i + div - 2





if __name__ == '__main__':

    N = int(eval(input()))

    print((main(N)))

def get_half_dividers(n):

    return {i for i in range(1, int(n ** 0.5) + 1) if n % i == 0}





N = int(eval(input()))



dividers = get_half_dividers(N)

print((min([max(0, d - 1) + max(0, (N // d) - 1) for d in dividers])))

import math


def is_prime(q):
    q = abs(q)
    if q == 2:
        return True
    if q < 2 or q & 1 == 0:
        return False
    return pow(2, q - 1, q) == 1


def main(n):
    if is_prime(n):
        return n - 1
    else:
        sqrt = int(math.sqrt(n))
        for i in range(sqrt, 1, -1):
            div, mod = divmod(n, i)
            if mod == 0:
                return i + div - 2


if __name__ == "__main__":
    N = int(eval(input()))
    print((main(N)))

def get_half_dividers(n):
    return {i for i in range(1, int(n**0.5) + 1) if n % i == 0}


N = int(eval(input()))
dividers = get_half_dividers(N)
print((min([max(0, d - 1) + max(0, (N // d) - 1) for d in dividers])))

-import math +def get_half_dividers(n): +    return {i for i in range(1, int(n**0.5) + 1) if n % i == 0} -def is_prime(q): -    q = abs(q) -    if q == 2: -        return True -    if q < 2 or q & 1 == 0: -        return False -    return pow(2, q - 1, q) == 1 - - -def main(n): -    if is_prime(n): -        return n - 1 -    else: -        sqrt = int(math.sqrt(n)) -        for i in range(sqrt, 1, -1): -            div, mod = divmod(n, i) -            if mod == 0: -                return i + div - 2 - - -if __name__ == "__main__": -    N = int(eval(input())) -    print((main(N))) +N = int(eval(input())) +dividers = get_half_dividers(N) +print((min([max(0, d - 1) + max(0, (N // d) - 1) for d in dividers])))