CodeEff/ECCO huggingface dataset:
# Original solution
n=int(eval(input()))
ans=float('inf')
for i in range(1,int(n**0.5)+2):
  if n%i==0:
    ans=min(ans,n//i-1+i-1)
print(ans)


# Optimized solution
n=int(eval(input()))
ans=float('inf')
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        ans=min(ans,i-1+n//i-1)
print(ans)
# Original solution
from math import sqrt
n = int(eval(input()))
stop = int(sqrt(n)) + 1
min_count = 10 ** 100
for a in range(1, stop):
    if n % a != 0:
        continue
    else:
        b = n // a
    count = a + b - 2
    if count < min_count:
        min_count = count
print(min_count)

# Optimized solution
n = int(eval(input()))
stop = int(n**0.5) + 1
min_count = 10 ** 100
for a in range(1, stop):
    if n % a != 0:
        continue
    else:
        b = n // a
    count = a + b - 2
    if count < min_count:
        min_count = count
print(min_count)
# Original solution
n = int(eval(input()))
stop = int(n**0.5) + 1
min_count = 10 ** 100
for a in range(1, stop):
    if n % a != 0:
        continue
    else:
        b = n // a
    count = a + b - 2
    if count < min_count:
        min_count = count
print(min_count)

# Optimized solution
n = int(eval(input()))
print((min(i + (n // i) - 2 for i in range(1, int(n**0.5) + 1) if n % i == 0)))
# Original solution
import math
n = int(eval(input()))
p = 10 ** 12
m = math.floor(math.sqrt(n))

for i in range(1,m + 1):
    if n % i == 0:
        j = n // i
        p = min(p,i-1+j-1)

print(p)

# Optimized solution
from math import sqrt
from math import floor
n = int(eval(input()))
ans = 10 ** 12
m = floor(sqrt(n))
for i in range(1,m+1):
    if n % i == 0:
        j = n // i
        ans = min(ans,i+j-2)
print(ans)
# Original solution
def prime_factors(n):       # 戻り値はiterable type
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            yield i             # whileループを進めるごとにイテレータに値を貯め続ける
    if n > 1:
        yield n

def min2(x,y):
    return x if x < y else y

from itertools import combinations

N = int(eval(input()))
P = list(prime_factors(N))
L = len(P) + 1
res =float("inf")

for k in range(L//2, 0, -1):
    for a in combinations(prime_factors(N), k):
        q = 1
        for p in a:
            q *= p
        res = min2((q - 1) + (N // q - 1), res)

print(res)

# Optimized solution
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def min2(x,y):
    return x if x < y else y

N = int(eval(input()))
P = make_divisors(N)
L = len(P) + 1
res =float("inf")

for p in P:
    res = min2((p - 1) + (N // p - 1), res)

print(res)
# Original solution
from functools import reduce
from itertools import combinations

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(eval(input()))
factor = [1] + prime_factorize(n)

ans = int(1e13)
for i in range(1, len(factor)//2 + 1):
    for c in combinations(factor, i):
        a = reduce(lambda x,y:x*y, c)
        b = n // a
        ans = min(ans, a + b - 2)
print(ans)

# Optimized solution
def factorize(n):
    a = []
    f = 2
    while f * f <= n:
        if n % f == 0:
            a.append((f, n//f))
        f += 1
    if not len(a):
        a.append((1, n))
    return a

n = int(eval(input()))
factor = factorize(n)

ans = int(1e13)
for fa in factor:
    a, b = fa
    ans = min(ans, a + b - 2)
print(ans)
# Original solution
n=int(eval(input()))
i=1
ans=10**13
while(i*i<=n):
    if(n%i==0):
        ans=min(ans,n/i+i-2)
    i+=1
print((int(ans)))

# Optimized solution
n=int(eval(input()))
i=1
ans=10**13
while(i*i<=n):
    if(n%i==0):
        ans=min(ans,n//i+i-2)
    i+=1
print(ans)
# Original solution
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(eval(input()))
    min = 10 ** 15
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0 and min > i + n // i - 2:
            min = i + n // i - 2
    print(min)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


# Optimized solution
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(eval(input()))

    min = 10 ** 15

    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            j = n // i
            if min > i + j - 2:
                min = i + j - 2

    print(min)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
# Original solution
import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')

# 約数の全列挙
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort(reverse=True)  # ソート
    return divisors

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

    divs = divisors(N)
    ans = INF
    for d in divs:
        M = N // d
        ans = min(ans, M - 1 + d - 1)

    print(ans)

sol()

# Optimized solution
N = int(eval(input()))

ans = N - 1
for i in range(1, int(N**0.5) + 10):
    if N % i == 0:
        j = N // i
        ans = min(ans, i + j - 2)

print(ans)
# Original solution
N = int(eval(input()))

ans = N - 1
for i in range(1, int(N**0.5) + 10):
    if N % i == 0:
        j = N // i
        ans = min(ans, i + j - 2)

print(ans)

# Optimized solution
N = int(eval(input()))

ans = 10**18
for i in range(1, int(N**0.5) + 10):
    if N % i > 0:
        continue
    j = N // i
    ans = min(ans, i + j - 2)
print(ans)
# Original solution
N = int(eval(input()))

ans = N - 1
for i in range(1, int(N**0.5) + 100):
    if N % i != 0:
        continue
    j = N // i
    ans = min(ans, i + j - 2)
print(ans)


# Optimized solution
N = int(eval(input()))

# 約数の全列挙
def divisors(n):
    divisors = []
    R = int(n**(0.5)) + 1
    for i in range(1, R):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    # divisors.sort(reverse=True)  # ソート
    return divisors

ans = 10**18
for d in divisors(N):
    k = N // d

    ans = min(ans, d + k - 2)
print(ans)
# Original solution
N = int(eval(input()))

n = int(N**0.5) + 1
A = 0
B = 0
b = 0
for a in range(1, n):
    if N % a == 0:
        b = N // a
        A = a
        B = b
ans = (A - 1) + (B - 1)
print(ans)

# Optimized solution
N = int(eval(input()))

n = int(N**0.5) + 1

for a in range(1, n):
    if N % a == 0:
        b = N // a
        ans = (a - 1) + (b - 1)
print(ans)
# Original solution
import itertools

a = int(eval(input()))

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

arr0 = factorization(a) 


arr1 = [arr0[i][0] for i in range(len(arr0))]
arr2 = [arr0[i][1] for i in range(len(arr0))]

ab = []
for i in range(len(arr1)):
    for j in range(arr2[i]):
        ab.append(arr1[i])

abc = []
for i in range(1,sum(arr2)+1):
    abc.extend(list(itertools.combinations(ab, i)))

abcd = []

for i in range(len(abc)):
    g = 1
    for j in range(len(abc[i])):
        g *= abc[i][j]
    
    abcd.append(g)


abcde = [[i,a//i] for i in abcd]
abcdef = [sum(abcde[i]) for i in range(len(abcde))]
print((min(abcdef)-2))

# Optimized solution
import itertools

a = int(eval(input()))

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

    # divisors.sort()
    return divisors

ab = [[i,a//i] for i in md(a)]
abc = [sum(ab[i]) for i in range(len(ab))]

print((min(abc)-2))
# Original solution
import math
N = int(eval(input()))
ans = 10**12
for i in range(1,10**6+1):
  j = math.ceil(N/(i+1))
  if (1+i)*j == N:
    ans = min(i+j-1,ans)
  if i == 10**6 and ans == 10**12:
    ans = N-1
    break
print(ans)

# Optimized solution
N = int(eval(input()))
ans = 10**12
for i in range(1,10**6+1):
  j = N//i
  if i*j == N:
    ans = min(i+j-2,ans)
  if i == 10**6 and ans == 10**12:
    ans = N-1
    break
print(ans)
# Original solution
N = int(eval(input()))

def prime_factorization(n):
    factor = []
    f = 2
    while f ** 2 <= n:
        if n % f == 0:
            factor.append(f)
            n //= f
        else:
            f += 1
    if n > 1:
        factor.append(n)
    return factor

p = prime_factorization(N)
from itertools import combinations as cb
from functools import reduce
from operator import mul

s = N+1
for i in range(1, len(p)//2+1):
    for j in cb(p, i):
        A = reduce(mul, j)
        B = N//A
        s = min(s, A+B)

print((s-2))

# Optimized solution
N = int(eval(input()))
S = N+1
from math import sqrt
for a in range(int(sqrt(N))+2, 0, -1):
    b, y = divmod(N, a)
    if y != 0:
        continue
    S = min(S, a+b)
print((S-2))
# Original solution
N=int(eval(input()))
bar=10**12

def f(x):
  d=[]
  for i in range(1,int(x**0.5)+1):
    if x%i==0:
      d.append(i)
      if i!=x//i:
        d.append(x//i)
  d.sort()
  return d

for i in f(N):
  for j in f(N):
    if i*j==N and i+j<bar:
      bar=i+j
      x=i
      y=j

print((x-1+y-1))
 

# Optimized solution
N=int(eval(input()))
bar=10**12
d=[]
for i in range(1,int(N**0.5)+1):
  if N%i==0 and i+N//i<bar:
    d.append(i+N//i)
    bar=i+N//i
#print(d)
print((min(d)-2))
# Original solution
n = int(eval(input()))

import math
a = int(math.sqrt(n))

point = 1
for i in range(1,a+1):
  if n%i == 0:
    point = i
    
distance = (point-1) + int(n/point)-1
print(distance)

# Optimized solution
n = int(eval(input()))
a = int(n**0.5)
n1 = 1
n2 = 1
for i in range(a,0,-1):
  if n%i==0: 
    n1 = i
    break
n2 = n//n1
print((n2+n1-2))
# Original solution
N=int(eval(input()))

from itertools import combinations
import math

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

d=make_divisors(N)

if math.sqrt(N)**2 ==N:
    d.append(int(math.sqrt(N)))

dist=float('inf')
for i in d:
    j = N//i
    if i * j ==N:
        dist = min(dist,i+j-2)

print(dist)
    

# Optimized solution
N=int(eval(input()))

from itertools import combinations
import math

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

d=make_divisors(N)

if math.sqrt(N) in d:
    d.append(int(math.sqrt(N)))

dist=float('inf')
for i in d:
    j = N//i
    if i * j ==N:
        dist = min(dist,i+j-2)

print(dist)
# Original solution
#ABC 144 C - Walk on Multiplication Table
N = int(eval(input()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
from itertools import combinations
import functools
import operator
P = prime_factorize(N)
m = N+1
memo = []
for i in range(1,len(P)+1):
    L1 = list(combinations(P,i))
    L1 = [list(l) for l in L1]
    for l in L1:
        if l not in memo:
            memo.append(l)
            s1 = functools.reduce(operator.mul,l)
            s2 = N/s1
            if s1+s2 <=m:
                m = s1+s2
print((int(m-2)))

# Optimized solution
N = int(eval(input()))
ans = N*3
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        s1 = i
        s2 =N/i
        
        if ans > s1+s2:
            ans =int(s1+s2)
print((ans-2))
# Original solution
n = int(eval(input()))
divisors = []
for i in range(1, int(pow(n, 0.5)) + 1):
    if n % i == 0:
        divisors.append([i, n // i])
    divisors = sorted(divisors, key= lambda x:x[1])
res = 0
for i in divisors[0]:
    res += i - 1

print(res)

# Optimized solution
n = int(eval(input()))
divisors = []
for i in range(1, int(pow(n, 0.5)) + 1):
    if n % i == 0:
        divisors.append([i, n // i])
divisors = sorted(divisors, key= lambda x:x[1])
res = 0

for i in divisors[0]:
    res += i - 1

print(res)
# Original solution
n = int(eval(input()))
divisors = []
for i in range(1, int(pow(n, 0.5)) + 1):
    if n % i == 0:
        divisors.append([i, n // i])
divisors = sorted(divisors, key= lambda x:x[1])
res = 0

for i in divisors[0]:
    res += i - 1

print(res)

# Optimized solution
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


# nの約数を列挙列挙する
def make_divisors(n):
    divisors = []
    for i in range(1, int(pow(n, 0.5)) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors


def resolve():
    n = int(eval(input()))

    div = make_divisors(n)

    res = f_inf
    for i in div:
        cost = i + n // i - 2
        res = min(res, cost)

    print(res)


if __name__ == '__main__':
    resolve()
# Original solution
from math import sqrt
n=int(eval(input()))
for i in range(int(sqrt(n)+1),-1,-1):
  if n%i==0:
    print((i+(n//i)-2))
    break

# Optimized solution
#C
from math import sqrt
n=int(eval(input()))
for i in range(int(sqrt(n)+1),-1,-1):
    if n%i==0:
        print((i+(n//i)-2))
        break
# Original solution
import math
n = int(eval(input()))
mini = 1000000000000000
for i in range(1, math.ceil(math.sqrt(n))+1):
  if n % i == 0 and ((n/i + i) - 2) < mini:
    mini = ((n/i + i) - 2)
print((int(mini)))

# Optimized solution
import math
n = int(eval(input()))
mini = n+2
for i in range(1, int(math.sqrt(n)+1)):
   if not n%i:
      if i + int(n/i) -2 < mini:
               mini = i + int(n/i) -2
print(mini)
# Original solution
import math
n=int(eval(input()))

for i in reversed(list(range(1,int(math.sqrt(n))+1))):
  if n%i == 0:
    ans = i+n//i-2
    break
print(ans)


# Optimized solution
import math
n=int(eval(input()))
r=int(math.sqrt(n))

while n%r!=0:
  r-=1
print((n//r+r-2))
# Original solution
N = int(eval(input()))

ans=N
for i in range(1, int(N**0.5+1)):
    if N%i==0:
        a = N/i
        b = N/a
        up_ans = a + b -2
        ans = min(ans, up_ans)
    else:
        continue
print((int(ans)))

# Optimized solution
N = int(eval(input()))
for i in range(int(N**0.5), 0 , -1):
    if N%i == 0:
        print((int(N/i + i -2)))
        break
# Original solution
n=int(eval(input()))
 
list=[]
 
for i in range(1,n+1):
    if len(list) == 1 and i>int(n/i):
        ans=(list[-1][0]-1)+(list[-1][1]-1)
        break
    a=n%i

    if a == 0:
        if(i<n/i):
            list.append([i,int(n/i)])
            if list[-1][0] == list[-1][1]:
                ans=(list[-1][0]-1)+(list[-1][1]-1)
        else:
            list.append([int(n/i),i])
            if len(list) == 1:
                ans=(list[-1][0]-1)+(list[-1][1]-1)
                break
            if list[-1]==list[-2]:
                ans=(list[-1][0]-1)+(list[-1][1]-1)
print(ans)

# Optimized solution
import math

n = int(eval(input()))

for i in range(int(math.sqrt(n)), 0, -1):
  if n % i == 0:
    print((int(i + n / i - 2)))
    break
# Original solution
N = int(eval(input()))

c = 1
ans = 10**18
while c <= N**0.5:
    if N%c == 0:
        ans = min(ans, c+N//c)
    c += 1
    
print((ans-2))

# Optimized solution
N = int(eval(input()))

ans = N
i = 1
while i <= N**0.5:
    if N%i == 0:
        ans = min(ans, i+N//i-2)
    i += 1

print(ans)
# Original solution
import math

N = int(eval(input()))
A = []
for i in range(2,int(math.sqrt(N))+1):
    if N%i == 0:
        for j in range(1,N//2+1):
            if N == i * j:
                A.append(i + j - 2)
if not A:
    print((N-1))
else:
    print((min(A)))

# Optimized solution
import math

N = int(eval(input()))
A = []
for i in range(2,int(math.sqrt(N))+1):
    if N%i == 0:
        A.append(i + (N//i) - 2)
if not A:
    print((N-1))
else:
    print((min(A)))
# Original solution
import math
A = int(eval(input()))
B = int(math.sqrt(A))
count = 0
for i in reversed(list(range(1,B+1))):
	if count == 0:
		if A % i == 0:
			print((int(i+A/i-2)))
			count += 1

# Optimized solution
import math

N=int(eval(input()))
P=math.sqrt(N)
C=float("inf")
for i in range (1,int(P+1)):
	if N%i==0:
		C=min(C,(i+N//i))
print((C-2))
# Original solution
import math

N=int(eval(input()))
P=math.sqrt(N)
C=float("inf")
for i in range (1,int(P+1)):
	if N%i==0:
		C=min(C,(i+N//i))
print((C-2))

# Optimized solution
import math

N=int(eval(input()))
M=int(math.sqrt(N))
ans=float("inf")
for i in range(1,M+1):
	if N%i==0:
		ans=min(ans,N//i+i)
print((ans-2))
# Original solution
n = int(eval(input()))

t = []
for i in range(1, int(n**0.5+1)):
   if n % i == 0:
      t.append(int(i+n/i))

print((min(t) - 2))


# Optimized solution
def make_divisors(n):
   divisors = []
   for i in range(1, int(n**0.5)+1):
      if n % i == 0:
         divisors.append([i, n // i])

   return divisors


n = int(eval(input()))

divisors = make_divisors(n)
print((min([sum(x)-2 for x in divisors])))
# Original solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
def main():
    N = int(eval(input()))
    ans = 10e+12 
    max_sq = int(math.sqrt(N)+1)
    for i in range(1, max_sq):
        if N % i == 0:
            j = N // i
            ans = min(ans, i+j-2)
    print(ans)
main()



# Optimized solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
def main():
    N = int(eval(input()))
    ans = N-1
    max_sq = int(math.sqrt(N)+1)
    for i in range(1, max_sq):
        if N % i != 0:
            continue
        j = N // i
        ans = min(ans, i+j-2)
    print(ans)
main()
# Original solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
def main():
    N = int(eval(input()))
    ans = N-1
    max_sq = int(math.sqrt(N)+1)
    for i in range(1, max_sq):
        if N % i != 0:
            continue
        j = N // i
        ans = min(ans, i+j-2)
    print(ans)
main()



# Optimized solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return eval(input())
def main():
    N = I()
    ans = N - 1
    max_sq = int(math.sqrt(N)) + 1
    for i in range(1, max_sq):
        if N % i != 0:
            continue
        j = N // i
        ans = min(ans, i+j-2)
    print(ans)
main()
# Original solution
n = int(eval(input()))
def divisor(n): 
    i = 1
    a = 0
    b = 0
    out = float('inf')
    while i * i <= n:
        if n%i == 0:
            a = i
            b = n//i
        if a+b < out:
          out = a+b
        i += 1
    return out
print((divisor(n)-2))

# Optimized solution
n = int(eval(input()))
def divisor(n): 
    i = 1
    out = float('inf')
    while i * i <= n:
        if n%i == 0:
          out = min((i+n//i),out)
        i += 1
    return out
print((divisor(n)-2))
# Original solution
N=int(eval(input()))
L=float("inf")
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        x,y=i,N//i
        l=x+y-2
        L=min(L,l)
print(L)

# Optimized solution
N=int(eval(input()))
ans=min(i-1+N//i-1 for i in range(1,int(N**0.5)+1) if N%i==0)
print(ans)
# Original solution
n=int(eval(input()))
ans=float('inf')
a=1
while n**0.5>=a:
  if n%a==0:
    ans=min(ans,a+n//a-2)
  a+=1
print(ans)


# Optimized solution
n=int(eval(input()))
ans=float('inf')
for a in range(1,int(n**0.5+1)):
  if n%a==0:
    ans=min(ans,a+n//a-2)
print(ans)
# Original solution
n = int(eval(input()))
ans = n
for i in range(1,int(n**.5)+2):
  if n%i == 0:
    ans = min(ans, i + n//i - 2)
print(ans)

# Optimized solution
def divisor(n):
    ass = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            ass.append(n//i)
    return sorted(ass)

n = int(eval(input()))
p = divisor(n)
ans = n + 10
for x in p:
  if x*x > n:
    break
  y = n//x
  if ans > y+x:
    ans = y+x
print((ans - 2))
# Original solution
N = int(eval(input()))
sqN = int(N**0.5)+1
for i in range(sqN,0,-1):
    if N % i == 0:
        ans = i+N//i
        break

print((ans-2))

# Optimized solution
# 約数s
def make_divisors(n):
    divisors = []
    ret = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ret.append((i,n//i))
    return ret

if __name__ == "__main__":
    n = int(eval(input()))
    ret = make_divisors(n)
    # print(ret)
    ans = 10**18
    for a,b in ret:
        ans = min(a+b, ans)
    print((ans-2))
# Original solution
import math 

N=int(eval(input()))

li=[]
l=0
m=0

for i in range(math.floor(math.sqrt(N))):
  if N%(i+1)==0:
    l=i
    m=N/(i+1)-1
    li.append(l+m)
  else:
    pass

print((int(min(li))))



# Optimized solution
N=int(eval(input()))

answer=0

for i in range(int(pow(N,1/2)),0,-1):
    if N%i==0:
        answer=(i-1)+(N//i-1)
        break
print(answer)
# Original solution
def main():
    N = int(eval(input()))

    st = [N + 1]  # (1,N)
    d = 2
    while d * d <= N:
        if N % d == 0:
            st.append(d + N // d)  # (d, N // d)
        d += 1

    print((min(st) - 2))


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N = int(eval(input()))

    ans = N - 1

    d = 1
    while d * d <= N:
        if N % d == 0:
            ans = min(ans, d + N // d - 2)
        d += 1

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
import math

n=int(eval(input()))
num=math.ceil(math.sqrt(n))

c=n+2
for i in range(1,num+1):
      if n%i==0 and (i+n//i)<c:
            a=i
            b=n//i
            c=a+b

print((a+b-2))


# Optimized solution
import math
n=int(eval(input()))
num=math.ceil(math.sqrt(n))
L=max([i for i in range(1,num+1) if n%i==0])
print((L+n//L-2))
# Original solution
import math
n=int(eval(input()))
num=math.ceil(math.sqrt(n))
L=max([i for i in range(1,num+1) if n%i==0])
print((L+n//L-2))

# Optimized solution
n=int(eval(input()))


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

    divisors.sort()
    return divisors

L=make_divisors(n)

s=float('inf')
for i in L:
      s=min(s,i+(n//i))

print((s-2))
# Original solution
import math
n=int(eval(input()))

to=int(math.sqrt(n))
a=n*2
for i in range(1,to+1):
    if n%i==0:
        a=min(a,n//i+i)

print((a-2))

# Optimized solution
import math
n=int(eval(input()))
L=[]
for i in range(1,int(math.sqrt(n))+2):
   if n%i==0:
      L.append((i,n//i))
ans=float("inf")
for i in L:
   ans=min(ans,i[0]+i[1]-2)
print(ans)
# Original solution
n=int(eval(input()))
n2=int(n**0.5)
for n3 in range(n2,0,-1):
    if n%n3==0:
        n4=n/n3
        n5=int((n3-1)+(n4-1))
        print(n5)
        break

# Optimized solution
n=int(eval(input()))

n2=int(n**0.5)
abmin=n
for i in range(1,n2+1):
    if n%i==0:
        ab=n//i+i-2
        abmin=min(ab,abmin)
        
print(abmin)