import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



import numpy as np



N = int(readline())



U = 10**6 + 100

div = np.arange(1,U,dtype=np.int64)

div = div[N%div==0]

answer = (div + (N//div)).min() - 2

print(answer)

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



import numpy as np



N = int(readline())



U = 10**6 + 100

x = np.arange(1,U,dtype=np.int64)

div = x[N%x==0]

answer = (div + (N//div)).min() - 2

print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
U = 10**6 + 100
div = np.arange(1, U, dtype=np.int64)
div = div[N % div == 0]
answer = (div + (N // div)).min() - 2
print(answer)

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
U = 10**6 + 100
x = np.arange(1, U, dtype=np.int64)
div = x[N % x == 0]
answer = (div + (N // div)).min() - 2
print(answer)

-div = np.arange(1, U, dtype=np.int64) -div = div[N % div == 0] +x = np.arange(1, U, dtype=np.int64) +div = x[N % x == 0]