import math

def is_prime(n):

    if n == 1: return False



    for k in range(2, int(math.sqrt(n)) + 1):

        if n % k == 0:

            return False

    return True



n = int(eval(input()))

a = 1

b = 1

tmp_ans = 0

ans = 10**12



if is_prime(n) == True:

    print((n - 1))

elif is_prime(n) == False:

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

        j = n // i

        if n == i*j:

            tmp_ans = (i-a) + (j-b)

            if tmp_ans < ans:

                ans = tmp_ans

    print(ans)

import math



n = int(eval(input()))

a = 1

b = 1

tmp_ans = 0

ans = 10**12



for i in range(1, int(math.sqrt(n))+1):

    j = n // i

    if n == i*j:

        tmp_ans = (i-a) + (j-b)

        if tmp_ans < ans:

            ans = tmp_ans

print(ans)

import math


def is_prime(n):
    if n == 1:
        return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True


n = int(eval(input()))
a = 1
b = 1
tmp_ans = 0
ans = 10**12
if is_prime(n) == True:
    print((n - 1))
elif is_prime(n) == False:
    for i in range(2, int(math.sqrt(n)) + 1):
        j = n // i
        if n == i * j:
            tmp_ans = (i - a) + (j - b)
            if tmp_ans < ans:
                ans = tmp_ans
    print(ans)

import math

n = int(eval(input()))
a = 1
b = 1
tmp_ans = 0
ans = 10**12
for i in range(1, int(math.sqrt(n)) + 1):
    j = n // i
    if n == i * j:
        tmp_ans = (i - a) + (j - b)
        if tmp_ans < ans:
            ans = tmp_ans
print(ans)

- - -def is_prime(n): -    if n == 1: -        return False -    for k in range(2, int(math.sqrt(n)) + 1): -        if n % k == 0: -            return False -    return True - -if is_prime(n) == True: -    print((n - 1)) -elif is_prime(n) == False: -    for i in range(2, int(math.sqrt(n)) + 1): -        j = n // i -        if n == i * j: -            tmp_ans = (i - a) + (j - b) -            if tmp_ans < ans: -                ans = tmp_ans -    print(ans) +for i in range(1, int(math.sqrt(n)) + 1): +    j = n // i +    if n == i * j: +        tmp_ans = (i - a) + (j - b) +        if tmp_ans < ans: +            ans = tmp_ans +print(ans)