def main():

    N = int(eval(input()))



    def trial_division(n):

        divs = []

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

            if n % i == 0:

                divs.append(i)

                if i != n//i:

                    divs.append(n//i)

        return divs



    divs = trial_division(N)

    d = len(divs)

    ans = float('inf')

    for i in range(d):

        for j in range(i, d):

            if divs[i] * divs[j] == N:

                ans = min(ans, divs[i] - 1 + divs[j] - 1)

    print(ans)





if __name__ == '__main__':

    main()

def main():

    N = int(eval(input()))



    def trial_division(n):

        divs = []

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

            if n % i == 0 and i != n//i:

                divs.append((i, n//i))

            elif n % i == 0 and i == n//i:

                divs.append((i, i))

        return divs

    divs = trial_division(N)

    ans = 10**13

    for d1, d2 in divs:

        ans = min(ans, d1 + d2 - 2)

    print(ans)





if __name__ == '__main__':

    main()

def main():
    N = int(eval(input()))

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

    divs = trial_division(N)
    d = len(divs)
    ans = float("inf")
    for i in range(d):
        for j in range(i, d):
            if divs[i] * divs[j] == N:
                ans = min(ans, divs[i] - 1 + divs[j] - 1)
    print(ans)


if __name__ == "__main__":
    main()

def main():
    N = int(eval(input()))

    def trial_division(n):
        divs = []
        for i in range(1, int(n**0.5) + 1):
            if n % i == 0 and i != n // i:
                divs.append((i, n // i))
            elif n % i == 0 and i == n // i:
                divs.append((i, i))
        return divs

    divs = trial_division(N)
    ans = 10**13
    for d1, d2 in divs:
        ans = min(ans, d1 + d2 - 2)
    print(ans)


if __name__ == "__main__":
    main()

-            if n % i == 0: -                divs.append(i) -                if i != n // i: -                    divs.append(n // i) +            if n % i == 0 and i != n // i: +                divs.append((i, n // i)) +            elif n % i == 0 and i == n // i: +                divs.append((i, i)) -    d = len(divs) -    ans = float("inf") -    for i in range(d): -        for j in range(i, d): -            if divs[i] * divs[j] == N: -                ans = min(ans, divs[i] - 1 + divs[j] - 1) +    ans = 10**13 +    for d1, d2 in divs: +        ans = min(ans, d1 + d2 - 2)