def main():

    N = int(eval(input()))

    i = 2

    ans = N + 1

    while i ** 2 <= N:

        if N % i == 0:

            ans = min(i + N / i, ans)

        i += 1

    print((int(ans - 2)))





if __name__ == '__main__':

    main()
def main():

    n = int(eval(input()))

    f = []

    i = 2

    while i * i <= n:

        if n % i == 0:

            f.append(i)

            if i * i != n:

                f.append(n // i)

        i += 1

    if n != 1:

        f.append(n)

    f.sort()

    answer = float("inf")

    for ff in f:

        answer = min(answer, ff + n // ff - 2)

    print(answer)





if __name__ == '__main__':

    main()



def main():
    N = int(eval(input()))
    i = 2
    ans = N + 1
    while i**2 <= N:
        if N % i == 0:
            ans = min(i + N / i, ans)
        i += 1
    print((int(ans - 2)))


if __name__ == "__main__":
    main()

def main():
    n = int(eval(input()))
    f = []
    i = 2
    while i * i <= n:
        if n % i == 0:
            f.append(i)
            if i * i != n:
                f.append(n // i)
        i += 1
    if n != 1:
        f.append(n)
    f.sort()
    answer = float("inf")
    for ff in f:
        answer = min(answer, ff + n // ff - 2)
    print(answer)


if __name__ == "__main__":
    main()

-    N = int(eval(input())) +    n = int(eval(input())) +    f = [] -    ans = N + 1 -    while i**2 <= N: -        if N % i == 0: -            ans = min(i + N / i, ans) +    while i * i <= n: +        if n % i == 0: +            f.append(i) +            if i * i != n: +                f.append(n // i) -    print((int(ans - 2))) +    if n != 1: +        f.append(n) +    f.sort() +    answer = float("inf") +    for ff in f: +        answer = min(answer, ff + n // ff - 2) +    print(answer)