import math



def dictcheck(dict):

    min = 0

    for k,v in list(dict.items()):

        if k == 1:

            min = v

            break

        elif min == 0:

            min=(int(k)-1)+(int(v)-1)

        elif min > (int(k)-1)+(int(v)-1):

            min = (int(k)-1)+(int(v)-1)

        else:

            continue

    print(min)



def main():

    N = int(eval(input()))

    i = 2

    tmpdict= {}

    while i <= math.sqrt(N):

        if N % i == 0:

            tmpdata = {i:N/i}

            tmpdict.update(tmpdata)

            i+=1

        else:

            i+=1

    if len(tmpdict)==0:

        tmpdata = {1:N-1}

        tmpdict.update(tmpdata)

#    print(tmpdict)

    dictcheck(tmpdict)



if __name__ == "__main__":

    main()
#-*-coding:utf-8-*-

import sys

input=sys.stdin.readline



def main():

    n = int(eval(input()))

    ans=10**12

    for a in range(1,10**6+1):

        if n%a==0:

            b=n//a

        ans=min(ans,a+b-2)

    print(ans)



if __name__=="__main__":

    main()
import math


def dictcheck(dict):
    min = 0
    for k, v in list(dict.items()):
        if k == 1:
            min = v
            break
        elif min == 0:
            min = (int(k) - 1) + (int(v) - 1)
        elif min > (int(k) - 1) + (int(v) - 1):
            min = (int(k) - 1) + (int(v) - 1)
        else:
            continue
    print(min)


def main():
    N = int(eval(input()))
    i = 2
    tmpdict = {}
    while i <= math.sqrt(N):
        if N % i == 0:
            tmpdata = {i: N / i}
            tmpdict.update(tmpdata)
            i += 1
        else:
            i += 1
    if len(tmpdict) == 0:
        tmpdata = {1: N - 1}
        tmpdict.update(tmpdata)
    #    print(tmpdict)
    dictcheck(tmpdict)


if __name__ == "__main__":
    main()

# -*-coding:utf-8-*-
import sys

input = sys.stdin.readline


def main():
    n = int(eval(input()))
    ans = 10**12
    for a in range(1, 10**6 + 1):
        if n % a == 0:
            b = n // a
        ans = min(ans, a + b - 2)
    print(ans)


if __name__ == "__main__":
    main()

-import math +# -*-coding:utf-8-*- +import sys - -def dictcheck(dict): -    min = 0 -    for k, v in list(dict.items()): -        if k == 1: -            min = v -            break -        elif min == 0: -            min = (int(k) - 1) + (int(v) - 1) -        elif min > (int(k) - 1) + (int(v) - 1): -            min = (int(k) - 1) + (int(v) - 1) -        else: -            continue -    print(min) +input = sys.stdin.readline -    N = int(eval(input())) -    i = 2 -    tmpdict = {} -    while i <= math.sqrt(N): -        if N % i == 0: -            tmpdata = {i: N / i} -            tmpdict.update(tmpdata) -            i += 1 -        else: -            i += 1 -    if len(tmpdict) == 0: -        tmpdata = {1: N - 1} -        tmpdict.update(tmpdata) -    #    print(tmpdict) -    dictcheck(tmpdict) +    n = int(eval(input())) +    ans = 10**12 +    for a in range(1, 10**6 + 1): +        if n % a == 0: +            b = n // a +        ans = min(ans, a + b - 2) +    print(ans)