CodeEff/ECCO huggingface dataset:
# Original solution
n=int(eval(input()))

import math
l=[]
for a in range(1,int(math.sqrt(n))+1):
  if n%a==0:
    b=int(n/a)
    l.append(a+b-2)
    
print((min(l)))


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

import math
l=[]
v=n+1-2

for a in range(1,int(math.sqrt(n))+1):
  if n%a==0:
    b=int(n/a)
    temp=a+b-2
    if v>temp:
      v=temp
    
print(v)
# Original solution
n=int(eval(input()))

import math
l=[]
v=n+1-2

for a in range(1,int(math.sqrt(n))+1):
  if n%a==0:
    b=int(n/a)
    temp=a+b-2
    if v>temp:
      v=temp
    
print(v)


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

n = int(eval(input()))
b = 0
list = []
sqrt = math.ceil(math.sqrt(n))
for i in range(1,sqrt+1):
	if(n%i==0):
		b = i
print((b + (n//b) -2))

# Optimized solution
N = int(eval(input()))
ans=1e+18
for i in range(1,int(N**0.5+1)):
    if(N%i==0):
        ans = min(ans,int(i+N/i-2))
print(ans)
# Original solution
from functools import lru_cache


def factorize(n):
    f = []
    tmp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        while tmp % i == 0:
            f.append(i)
            tmp //= i
    if tmp != 1:
        f.append(tmp)
    if not f:
        f.append(n)
    return f


def distance(s):
    a, b = 1, 1
    for i, si in enumerate(s):
        if si == "0":
            a *= factors[i]
        else:
            b *= factors[i]
    return a + b - 2


@lru_cache()
def kp(i, s):
    if i == 0:
        return 0, s
    else:
        if distance("0" + s) < distance("1" + s):
            return kp(i - 1, "0" + s)
        else:
            return kp(i - 1, "1" + s)


def sa(f):
    d = 999999999999
    for i in range(2 ** len(f)):
        d = min(d, distance("{}{}".format("0" * (len(f) - 1), bin(i)[2:])[-len(f):]))
    return d


N = int(eval(input()))
factors = factorize(N)
print((sa(factors)))

# Optimized solution
from collections import defaultdict


def factorize(n):
    f = defaultdict(int)
    tmp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        while tmp % i == 0:
            f[i] += 1
            tmp //= i
    if tmp != 1:
        f[tmp] += 1
    if not f:
        f[n] += 1
    return f


def distance(s, d):
    a, b = 1, 1
    for i, si in enumerate(s):
        if si == "0":
            a *= factors[i]
            if a > d:
                return inf
        else:
            b *= factors[i]
            if b > d:
                return inf
    return a + b - 2


def answer(f, d):
    a = 1
    for i in f:
        a *= i
        if a > d:
            return inf
    return a + N // a - 2


def sa(f):
    d = inf
    for fi in f:
        d = min(d, answer(fi, d))
    return d


def comb(f):
    c = [[]]
    for k in f:
        ct = [[k] * i for i in range(1, f[k] + 1)]
        ci = c.copy()
        for cti in ct:
            for cii in ci:
                c.append(cii + cti)
    return [[1]] + c[1:]


# CONST = 1099511627776
N = int(eval(input()))
inf = 999999999999
factors = factorize(N)
print((sa(comb(factors))))
# Original solution
n=int(eval(input()))
ans=0
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        ans=n//i+i-2
print(ans)


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

# Optimized solution
n=int(eval(input()))
ans=n-1
for i in range(2,int(n**0.5)+1):
    if n%i==0:
        tmp=i+n//i-2
        ans=min(ans,tmp)
print(ans)
# Original 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)
if len(l) % 2 == 0:
  x = l[len(l) // 2 - 1]
  y = l[len(l) // 2]
  print((x + y - 2))
else:
  x = l[len(l) // 2]
  print((2 * (x-1)))

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

n = math.sqrt(N)
if n.is_integer():
  x = round(n) - 1
  print((2 * x))
else:
  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)
  if len(l) % 2 == 0:
    x = l[len(l) // 2 - 1]
    y = l[len(l) // 2]
    print((x + y - 2))
# Original solution
import math
N = int(eval(input()))

a = math.floor(N ** 0.5) + 1
ans = N + 1
for i in range(1, a):
  j = N // i
  if i * j == N and i + j - 2 < ans:
    ans = i + j - 2
  
print(ans)

# Optimized solution
import math
N = int(eval(input()))
a = math.floor(N ** 0.5)

ans = N
for x in range(1, a + 1):
  if N % x != 0: continue
  y = N // x
  if ans > x + y - 2:
    ans = x + y - 2
print(ans)
# Original solution
n = int(eval(input()))
x = int(n**0.5)
while n%x!=0:
    x-=1
x,y = x-1, n//x -1
print((x+y))

# Optimized solution
n = int(eval(input()))
x = int(n**0.5)
while n%x!=0: x-= 1
y = n//x
print((x-1+y-1))
# Original solution
n = int(eval(input()))
l = int(n**0.5)
while l:
    if n%l: l-=1
    else: break
print(((l-1)+(n//l-1)))

# Optimized solution
n = int(eval(input()))
x, y = 1, n
for i in range(1, int(n**0.5)+1):
        if n%i==0: x = i
y = n//x
print((x+y-2))
# Original solution
n = int(eval(input()))
min1 = 10**20
for i in range(1,int(n**0.5)+1):
  if n/i %1 == 0:
    j = n//i
    min1 = min(min1,i+j)
print((min1-2))

# Optimized solution
n = int(eval(input()))
ans = 10**13
for i in range(1,int(n**0.5//1)+1):
    if n%i == 0:
        ans = min(ans,i+n//i-2)
print(ans)
# Original solution
import itertools
n = int(eval(input()))
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table
l = []
for it in itertools.combinations_with_replacement(divisor(n),2):
    if it[0] * it[1] == n:
        l.append(it[0] + it[1] -2)
print((sorted(l)[0]))

# Optimized solution
import itertools
n = int(eval(input()))
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table
d = divisor(n)
l = float('inf')
for i in range(len(d)):
    l = min(n // d[i] + d[i] - 2,l)
print(l)
# Original solution
n = int(eval(input()))

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

# Optimized solution
# 2019-11-19 19:43:48(JST)
import sys
# import collections
import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    n = int(sys.stdin.readline().rstrip())

    dist = n
    for i in range(1, math.floor(math.sqrt(n)) + 1):
        if n % i == 0:
            j = n // i
            dist = min(dist, i + j - 2)
    print(dist)

if __name__ == "__main__":
    main()
# Original solution
# 2019-11-19 19:43:48(JST)
import sys
# import collections
import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    n = int(sys.stdin.readline().rstrip())

    dist = n
    for i in range(1, math.floor(math.sqrt(n)) + 1):
        if n % i == 0:
            j = n // i
            dist = min(dist, i + j - 2)
    print(dist)

if __name__ == "__main__":
    main()


# Optimized solution
import sys

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

n = int(sys.stdin.readline().rstrip())

def main():
    res = divisors(n)
    print((res[-1] + res[-2] - 2))

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

from functools import reduce
from operator import mul

def prod(arr):
    return reduce(mul, arr, 1)

def fancy(arr, index):
    output = []
    for i, v in enumerate(index):
        if v:
            output.append(arr[i])
    return output

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

N = int(eval(input()))
factors = prime_factorize(N)
selectors = [list(map(bool, list(map(int, list("{0:b}".format(i).zfill(len(factors))))))) for i in range(1, 2**len(factors))]
combinations = [(prod(fancy(factors, selector)), N//prod(fancy(factors, selector))) for selector in selectors]
distances = [combination[0]-1 + combination[1]-1 for combination in combinations]
print((min(distances)))


# Optimized solution
N = int(eval(input()))
minstep = 9999999999999999999999999999999
for i in range(1, int(N**0.5+1)):
  if N%i == 0:
    minstep = min(minstep, i+N//i-2)
print(minstep)
# Original solution
N = int(eval(input()))
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct
A = factorize(N)
if len(A) == 1:
    ans = N-1
else: 
    ans = 9999999999999999999999
    from itertools import permutations as P
    from functools import reduce
    for i in range(1,len(A)):
        l1 = list(P(A,i))
        for l1_temp in l1:
            l2 = list([x for x in A if x not in l1])
            ans_1 = reduce(lambda x,y:x * y,l1_temp)
            ans_2 = N//ans_1
            ans_temp = (ans_1 + ans_2 -2)
            ans = min(ans,ans_temp)
print(ans)

# Optimized solution
from math import ceil, sqrt
N = int(eval(input()))
for i in range(ceil(sqrt(N)),0,-1):
    if N%i == 0:
        print((i + N//i -2))
        break
# Original solution
n = int(eval(input()))
ans = n -1
prime = []

while n != 1:
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            prime.append(i)
            n /= i
            break
    else:
        prime.append(int(n))
        n = 1

for bit in range(1 << len(prime)):
    a = 1
    b = 1

    for i in range(len(prime)):
        if bit >> i & 1:
            a *= prime[i]
        else:
            b *= prime[i]

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

print(ans)

# Optimized solution
import sys

n = int(eval(input()))

for i in range(int(n**0.5),0,-1):
    if n % i == 0:
        print((n//i + i - 2 ))
        sys.exit()
# Original solution
import sys

n = int(eval(input()))

for i in range(int(n**0.5),0,-1):
    if n % i == 0:
        print((n//i + i - 2 ))
        sys.exit()

# Optimized solution
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())

    def enum_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

    divs = enum_divisors(N)

    ans = INF
    for div1 in divs:
        div2 = N // div1
        score = (div1 + div2 - 2)
        ans = min(score, ans)

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
from operator import mul
from functools import reduce
import itertools
import copy

N = int(eval(input()))

# N = i*jをみつける
# (i, j)


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

def remove_dup_list(tmplist):
    return list(map(list, set(map(tuple, tmplist))))


prime_list = prime_factorize(N)

if len(prime_list)<=1:
    result = N-1
else:
    result = 10**12


#print(prime_list)
for i in range(len(prime_list)//2):
    # i個抽出
    tmp = list(itertools.combinations(prime_list, i+1))
    tm = remove_dup_list(list(map(list, tmp)))
    #print(tm)
    for _ in tm:
        temp_origin_list = copy.copy(prime_list)
        for item in _:
            temp_origin_list.remove(item)
        result = min(result, reduce(mul, _) + reduce(mul, temp_origin_list) - 2)

print(result)



# Optimized solution
import math
N = int(eval(input()))
result = N
for i in range(1, int(math.sqrt(N))+2):
    if N % i == 0:
        result = min(result, i - 1 + N//i - 1)
print(result)
# Original solution
from copy import deepcopy

N = int(eval(input()))

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

n = prime_factors(N)

dicts = {}
for x in range(2**len(n)):
    flgs = bin(x)[2:]
    if len(flgs) < len(n):
        flgs = ''.join(['0' for _ in range(len(n)-len(flgs))]) + flgs
    flgs = flgs[::-1]
    
    a = 1
    b = 1
    for i in range(len(flgs)):
        if flgs[i] == '1':
            a *= n[i]
        else:
            b *= n[i]
    dicts[a+b] = {'a':deepcopy(a), 'b':deepcopy(b)}

            
min_ab = min(dicts.keys())
print((dicts[min_ab]['a'] + dicts[min_ab]['b'] - 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
 
n = sorted(make_divisors(N))

sum_yakusuu = N
for _n in n:
    if _n == 1:
        continue
    if _n+N/_n < sum_yakusuu:
        sum_yakusuu = int(_n+N/_n)
        bef_n = _n
    else:
        if len(n) == 2:
            print((int(_n-1)))
        else:
            print((int(bef_n+N/bef_n-2)))
        break
# Original solution
import math

N = int(eval(input()))

answer = N + 1
for a in range(1, math.floor(math.sqrt(N)) + 1):
    if  N % a == 0:
        answer = min(answer, int(a + N / a) - 2)
print(answer)

# Optimized solution
import math
N = int(eval(input()))
print((min([a + N // a - 2 for a in range(math.floor(math.sqrt(N)) + 1, 0, -1) if N % a == 0])))
# Original solution
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.extend([b]*e)
        b, e = b + 1, 0
    if n > 1:
        fct.extend([n]*1)
    return fct

N = int(eval(input()))
arr = factorize(N)
M = len(arr)
ans = N
for i in range(2**(M-1)):
    A = 1
    B = 1
    for j in range(M):
        if (i>>j)&1:
            A *= arr[j]
    B = N//A
    A = max(A-1,0)
    B = max(B-1,0)
    ans = min(ans,A+B)

print(ans)

# Optimized solution
import math
N = int(eval(input()))
tmp = math.ceil(N**(1/2))
ans = N
for i in range(1,tmp+1):
    if N%i == 0:
        A = max(N//i-1,0)
        B = max(i-1,0)
        ans = min(ans,A+B)

print(ans)
# Original solution
import math
N = int(eval(input()))
tmp = math.ceil(N**(1/2))
ans = N
for i in range(1,tmp+1):
    if N%i == 0:
        A = max(N//i-1,0)
        B = max(i-1,0)
        ans = min(ans,A+B)

print(ans)

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

ans = N

for i in range(1,int(N**(1/2))+1):
  if N%i == 0:
    A = i-1
    B = N//i-1
    ans = min(ans,A+B)
print(ans)
# Original solution
n = int(eval(input()))
tmp = 1
 
for i in range(1,10**6+1):
  if n%i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif tmp == 1 and i >= n/i:
    break
      
print((tmp + (n//tmp) -2))

# Optimized solution
n = int(eval(input()))
tmp = 1
 
for i in range(1,10**6+1): #10**12とかにしてしまうとTLE　
  #たとえばn=2*大きい素数である時を考えると，この時は全回ししてまう
  if n%i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif tmp == 1 and i >= n/i:
    break
      
print((tmp + (n//tmp) -2))
# Original solution
n = int(eval(input()))
tmp = 1
 
for i in range(1,10**6+1):
  if n%i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif i >= n/i:
    break
      
print((tmp + (n//tmp) -2))

# Optimized solution
n = int(eval(input()))
tmp = 1
 
for i in range(1,10**10):
  if n%i == 0:
    if i <= n//i:
      tmp  = i
    else:
      break
  elif i >= n/i:
    break
      
print((tmp + (n//tmp) -2))
# Original solution
import itertools

def primes(n):
    l = []
    i = 2
    while i <= n**(1/2):
        while n % i == 0:
            n //= i
            l.append(i)
        i += 1
    l.append(n)
    return l

def mul(l):
    result = 1
    for i in l:
        result *= i
    return result

n = int(eval(input()))

per = list(itertools.permutations(primes(n)))

i,j = 1,n
for p in per:
    for k in range(len(p)):
        s,t = mul(p[:k]), mul(p[k:])
        if abs(s-t) < abs(i-j):
            i,j = s,t

print((i+j-2))


# Optimized solution
import itertools

def primes(n):
    l = []
    i = 2
    while i <= n**(1/2):
        while n % i == 0:
            n //= i
            l.append(i)
        i += 1
    l.append(n)
    return l

def mul(l):
    result = 1
    for i in l:
        result *= i
    return result

n = int(eval(input()))

per = list(set(itertools.permutations(primes(n))))

i,j = 1,n
for p in per:
    for k in range(len(p)):
        s,t = mul(p[:k]), mul(p[k:])
        if abs(s-t) < abs(i-j):
            i,j = s,t

print((i+j-2))
# Original solution
import itertools

def primes(n):
    l = []
    i = 2
    while i <= n**(1/2):
        while n % i == 0:
            n //= i
            l.append(i)
        i += 1
    if n > 1:
        l.append(n)
    return l

def mul(l):
    result = 1
    for i in l:
        result *= i
    return result

n = int(eval(input()))

prime_list = primes(n)

i,j = 1,n
for m in range(len(prime_list)//2 + 1):
    cmb = set(itertools.combinations(prime_list, m))
    for c in cmb:
        s = mul(c)
        t = n//s
        if abs(s-t) < abs(i-j):
            i,j = s,t

print((i+j-2))


# Optimized solution
import math

N = int(eval(input()))

ans = 10**15
for k in range(1, int(math.sqrt(N))+1):
    if N % k > 0:
        continue
    ans = min(ans, k + N//k - 2)
print(ans)
# Original solution
n = int(eval(input()))
s = int(n ** 0.5)
i = 0
while True:
    if n%(s + i) == 0:
        k = 1
        break
    if n%(s - i) == 0:
        k = -1
        break
    i += 1
s = s + i * k 
print(((s + n // s) - 2))

# Optimized solution
import math
N = int(eval(input()))
a = 1
b = 1
ran = int(math.floor(math.sqrt(N)))
m = 1
for i in range(1,ran+1):
    if N%i == 0:
        if i > m:
            m = i
print((int(m + N/m -2)))
# Original solution
def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1

# -------- #

data = int(eval(input()))
ng_flag = False
min_value = 9999999

if is_prime(data):
    print((data -1))
    exit(0)

for i in range(1, int(data / 2) + 1):
    if data % i == 0:
        validation = i + data / i
        if validation < min_value:
            min_value = validation
print((int(min_value-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)
            if i != n // i:
                divisors.append(n//i)
    return divisors

min_value = 1000000000000
data = int(eval(input()))
ng_flag = False
divisors_array = make_divisors(data)

if len(divisors_array) % 2 == 1:
    divisors_array.append(divisors_array[len(divisors_array)-1])
for i in range(0, len(divisors_array)):
    if(i % 2 == 0):
        first = divisors_array[i] -1 
        second = divisors_array[i+1] -1 
        if first + second < min_value:
            if i == 1:
                min_value = first + second
            else:
                min_value = first + second
print(min_value)
# Original solution
N = int(eval(input()))

m = 10**12
for i in range(1, 10**6+1):
  if N % i == 0:
    m = min(m, i + (N // i))
    
    
print((m-2))

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

# (1, 1)から(a, b)に至るまでの移動回数は(a+b−2)であることに注意すると、
# a*b=N を満たす(a, b)について(a+b−2)の最小値を求めればよい
# 対称性より、O(√N)
# 今回はN=O(10^12)なので間に合う

# a+b-2の最小値を求める
ans = N-1
for i in range(1, int(math.sqrt(N))+1):
  if N % i == 0:
    ans = min(ans, (N//i)+i-2)
    
print(ans)
# Original solution
n = int(eval(input()))
dv = float('inf')
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

div = make_divisors(n)
# print(make_divisors(n), len(make_divisors(n)))
# print(make_divisors(n)[169//2])
l = len(make_divisors(n))
# print(div)
if l % 2 == 0:
    for i in range(l//2):
        if dv > (div[i]-1) + (div[l-i-1]-1):
            dv = (div[i]-1) + (div[l-i-1]-1)
else:
    for i in range((l//2)+1):
        if dv > (div[i]-1) + (div[l-i-1]-1):
            dv = (div[i]-1) + (div[l-i-1]-1)

print(dv)

# 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

div = make_divisors(N)
if len(div) % 2 == 0:
    print(((div[len(div) // 2] - 1) + (div[len(div) // 2 - 1] - 1)))
else:
    print(((div[len(div) // 2] - 1)*2))
# Original solution
import math
import copy

n=int(eval(input()))

i=int(n**0.5)
j=0
# print(i)

for i in range(i+1,0,-1):
    # print(i)
    if n==i:
        print((n-1))
        break
    if n%i==0:
        j=n/i
        print((int(i+j-2)))
        break


# Optimized solution
def main():
    n = int(eval(input()))
    ans = -1
    for i in range(1,int(n**0.5)+1):
        if n % i == 0:
            a = i
            b = n // i
            if ans == -1:
                ans = a + b - 2
            else:
                ans = min(ans,a + b - 2)
    print(ans)
if __name__ == '__main__':
    main()
# Original solution
N = int(eval(input()))
curMin = 10**12+1
for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        chk = (i - 1) + (N//i - 1)
        if curMin <= chk:
            break
        else:
            curMin = min(curMin, (i - 1) + (N//i - 1))
print(curMin)

# Optimized solution
N = int(eval(input()))
ans = 10**18+1
for i in range(1, int(N**0.5)+1):
    if N % i != 0:
        continue
    j = N // i
    ans = min(ans, i+j-2)
print(ans)
# Original solution
n = int(eval(input()))
def factorize(n):
    b = 2
    fct = []
    end = int(n ** (0.5)) + 2
    for b in range(2, end):
      while n % b == 0:
        n //= b
        fct.append(b)
      if n == 1:
        break
    if n > 1:
      fct.append(n)
    return fct
 
fact = factorize(n)
dif = []
from itertools import combinations as com
for i in range((len(fact) + 1) // 2 + 1):
  for cands in com(fact, i):
    ans = 1
    for cand in cands:
      ans *= cand
    dif.append(n//ans + ans - 2)
print((min(dif)))

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

end = int(n**0.5) + 2
dif = []
for i in range(1, end):
  if n % i == 0:
    dif.append(abs(n//i + i) - 2)
print((min(dif)))
# Original solution
import math

n=int(eval(input()))
r=int(math.sqrt(n))
l=[]
for a in range(1,r+1):
    if n%a == 0:
        l.append(a+int(n/a)-2)
print((min(l)))


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

for a in range(1,math.ceil(math.sqrt(n))+1):
    if n % a == 0:
        ans=min(ans,a+(n//a)-2)
print(ans)