CodeEff/ECCO huggingface dataset:
# Original solution
n=int(eval(input()))
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)
if n==divisors[-1]**2:
    print((divisors[-1]*2-2))
else:
    print((divisors[-1]+divisors[-2]-2))

# Optimized solution
n=int(eval(input()))
divisors = []
def a(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            divisors.append(n//i)
    divisors.sort()
    return divisors
a(n)
x=len(divisors)//2
print((divisors[x]+divisors[x-1]-2))
# Original solution
n=int(eval(input()))
mini=float('inf')
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        mini=min(i+(n/i)-2,mini)
print((int(mini)))

# 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
lis=make_divisors(n)
x=lis[-1]
if n%x**2==0:
    print((x*2-2))
    exit()
print((lis[-1]+lis[-2]-2))
# Original solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def f(n):
        if n < 4:
            return [1,n]
        res = [1]
        i = 2
        while i*i <= n:
            if n%i == 0:
                res.append(i)
                m = n//i
                if m != i:
                    res.append(m)
            i += 1
        res.append(n)
        return res

    n = I()
    l = f(n)
    ans = float("inf")
    for x in l:
        m = x+n//x-2
        if m < ans:
            ans = m
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    for i in range(int(n**0.5)+2)[::-1]:
        if not n%i:
            print((n//i+i-2))
            return
    return

#Solve
if __name__ == "__main__":
    solve()
# Original solution
N=int(eval(input()))
move=int(N**.5)
while N%move!=0:
    move-=1
print((N//move+move-2))

# Optimized solution
N=int(eval(input()))
move=10**12
for n in range(1,int(N**.5)+1):
    if N%n==0:
        move=min(move,N//n+n-2)
print(move)
# Original solution
N = int(eval(input()))
root = int(N ** (1/2)) + 1
num = 1
for i in range(root, 0, -1):
    if N % i == 0:
        num = i
        break
num2 = N // num
print((num+num2-2))

# Optimized solution
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def make_divisors(n): # 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 = ir()
D = make_divisors(N)
answer = 10 ** 12
for d in D:
    e = N // d
    result = (d - 1) + (e - 1)
    if result < answer:
        answer = result

print(answer)
# Original solution
N = int(eval(input()))
ans = 10 ** 20
for i in range(1, 10 ** 6 + 1):
    if i ** 2 > N: break
    if N % i == 0:
        ans = min(ans, i + N // i - 2)
print(ans)

# Optimized solution
import sys
def solve():
    N = int(eval(input()))
    moveN = 10000000000000000000
    for i in range(1, N + 1):
        if i ** 2 > N: break
        if N % i == 0:
            moveN = min(i + (N // i) - 2, moveN)
    print(moveN)

    return 0

if __name__ == "__main__":
    solve()
# Original solution
from math import sqrt
N = int(eval(input()))
ans = float("inf")
for k in range(1,int(sqrt(N)+1)+1):
    if N%k == 0:
        ans = min(ans,k-1+N//k-1)
print(ans)


# Optimized solution
import math
N = int(eval(input()))
ans = 10**12 + 1
for k in range(1,math.floor(math.sqrt(N))+1):
    if N % k == 0:
        ans = min(ans,k+N//k-2)

print(ans)
# Original solution
import math
N = int(eval(input()))
ans = 10**12 + 1
for k in range(1,math.floor(math.sqrt(N))+1):
    if N % k == 0:
        ans = min(ans,k+N//k-2)

print(ans)


# Optimized solution
import math
N = int(eval(input()))
ans = 10**13
for k in range(1,math.floor(math.sqrt(N))+1):
    if N % k == 0:
        ans = min(ans,k+N//k-2)
print(ans)
# Original solution
import itertools

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

prime = prime_factorize(N)
min_cnt = 10**13
if len(prime) == 1:
    print((prime[0]-1))
else:
    for i in range(1,2 ** len(prime)-1):
        x = 1
        y = 1
        index = 0
        while index <= len(prime)-1:
            if i & 1 == 1:
                x *= prime[index] 
            else:
                y *= prime[index]
            i = i >> 1
            index += 1
        min_cnt = min(min_cnt, (x-1) + (y-1))
    print(min_cnt)




# 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

min_cnt = 10**13
divisor = make_divisors(N)

for i in range(len(divisor)):
    b = N // divisor[i]
    min_cnt = min(min_cnt, (divisor[i]-1 + b-1))
print(min_cnt)
# Original solution
n=int(eval(input()))
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""

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

ans=[]
for num,cnt in factorization(n):
  for _ in range(cnt):
    ans.append(num)
out=float('inf')
tmp=[]
for i in range(2**len(ans)//2):
  tmp1,tmp2=1,1
  for j in range(len(ans)):
    if i>>j&1:
      tmp1*=ans[j]
    else:
      tmp2*=ans[j]
  out=min(out,tmp1-1+tmp2-1)
print(out)

# Optimized solution
import math
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
a=make_divisors(n)
if len(a)%2==1:
  print((2*int(math.sqrt(n))-2))
if len(a)%2==0:
  b=a[len(a)//2-1]
  c=a[len(a)//2]
  print((b+c-2))
# Original solution
N = int(eval(input()))
s = N+1
import math
m = int(math.sqrt(N))+1
for i in range(1,m):
  if N%i==0:
    a = i
    b = N/a
    s = min(a+b, s)
print((int(s)-2))

# Optimized solution
N = int(eval(input()))
import math
n = int(math.sqrt(N))
s = 0
for i in range(1,n+1):
  if N%i == 0 and i > s:
    s = i
    
p = int(s+N/s-2)
print(p)
# Original solution
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    ret = float('inf')
    for i in range(1, 10000000):
        q, mod = divmod(N, i)
        if mod == 0:
            j = N // i
            ret = min(ret, ((j-1)+(i-1)))

    print(ret)


if __name__ == '__main__':
    main()

# Optimized solution
import sys
import os
import math

def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    max = int(math.sqrt(N) + 1)
    ret = float('inf')
    for i in range(1, max):
        q, mod = divmod(N, i)
        if mod == 0:
            j = N // i
            ret = min(ret, ((j-1)+(i-1)))

    print(ret)


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

def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

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

    max = int(math.sqrt(N) + 1)
    ret = float('inf')
    for i in range(1, max):
        q, mod = divmod(N, i)
        if mod == 0:
            j = N // i
            ret = min(ret, ((j-1)+(i-1)))

    print(ret)


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    T = int(math.sqrt(N))
    ret = float('inf')
    for i in range(1, T+1):
        if N % i == 0:
            ret = min(ret, N//i+i-2)
    print(ret)


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

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    ret = float('inf')
    I = int(math.sqrt(N)) * 10
    for i in range(1, I):
        if N%i == 0:
            j = N//i
            ret = min(ret, j + i - 2)

    print(ret)


if __name__ == '__main__':
    main()


# Optimized solution
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    m = int(N ** .5)
    while N % m != 0:
        m -= 1
    else:
        print((int(N / m + m - 2)))


if __name__ == '__main__':
    main()
# Original solution
a=int(eval(input()))
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        res=[]
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n//i)
        if res!=[]:
            divisors.append(res)
    return divisors
 
res=make_divisors(a)
my_min=0
for i in range(len(res)):
    if i==0:
        if len(res[i])==2:
            my_min=res[i][0]+res[i][1]
        else:
            my_min=(res[i][0]*2)
    else:
        if len(res[i])==2:
            my_min=min(my_min,res[i][0]+res[i][1])
        else:
            my_min=min(my_min,res[i][0]*2)
 
print((my_min-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
a=make_divisors(n)
#print(a)
if a[-1]**2==n:
    print((a[-1]*2-2))
else:
    print((a[-1]+a[-2]-2))
# Original solution
N = int(eval(input()))
dmin = 10**13
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        j = N//i
        dmin = min(dmin,abs(i-1)+abs(j-1))
print(dmin)

# Optimized solution
N = int(eval(input()))
cmin = 10**12
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        j = N//i
        cmin = min(cmin,i-1+j-1)
print(cmin)
# Original solution
N = int(eval(input()))
cmin = 10**12
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        j = N//i
        cmin = min(cmin,i-1+j-1)
print(cmin)

# Optimized solution
N=int(eval(input()))
dmin = 10**12+10
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        n = N//i
        dmin = min(dmin,i-1+n-1)
print(dmin)
# Original solution
N=int(eval(input()))
dmin = 10**12+10
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        n = N//i
        dmin = min(dmin,i-1+n-1)
print(dmin)

# Optimized solution
N = int(eval(input()))
dmin = N+N
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        dmin = min(dmin,i+N//i-2)
print(dmin)
# Original solution
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = float('inf')
for i in range(1,2*10**6):
    if (n/i).is_integer():
        res = min(res, i + n/i)
print((int(res-2)))


# Optimized solution
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue
from heapq import heappop, heappush
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
res = float('inf')
for i in range(1,int(math.sqrt(n))+1):
    if n%i == 0:
        res = min(res, i + n/i)
print((int(res-2)))
# Original solution
from functools import reduce
import itertools
def solve():
    N = int(eval(input()))
    primes = itertools.permutations(prime_factorize(N))

    min_sub = float('inf')
    for p in primes:
        p = [1] + list(p) + [1]
        for border in range(1, len(p)):
            a = reduce(lambda x, y: x*y, p[:border])
            b = reduce(lambda x, y: x*y, p[border:])
        
            if min_sub > a + b:
                min_sub = a + b 
    
    print((min_sub-2))

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                

if __name__ == '__main__':
    solve()


# Optimized solution
import math
def solve():
    N = int(eval(input()))
    rootN = math.sqrt(N)

    min_val = float('inf')
    for a in range(1, math.floor(rootN) + 1):
        if N % a == 0:
            b = N / a
            min_val = min(min_val, a + b - 2)
    
    print((int(min_val)))

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

#素因数分解
def prime_factorization(N):
    n=N
    a=2
    prime_factor=[]
    while a**2<=n:
        while n%a==0:
            prime_factor.append(a)
            n//=a
        a+=1
    if n>1:
        prime_factor.append(n)
    return prime_factor


# N=100
N=int(eval(input()))

a=1
b=N//a
dis=abs(a-b)

Li=prime_factorization(N)
# print(Li)

for p in range(2**len(Li)):
    bit=[]
    for e in range(len(Li)):
        if (p>>e)&1==1:
            bit.append(1)
        else:
            bit.append(0)
    # print(bit)
        proindex=[]
        for _ in range(len(bit)):
            if bit[_] ==1:
                proindex.append(_)
        _a=1
        for j in range(len(Li)):
            if proindex.count(j)==1:
                _a*=Li[j]
        _b=N//_a
        _dis=abs(_a-_b)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis
        if _a>N**0.5:
            break
# print(a,b)

print((a-1+b-1))

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

a=1
b=N//a
dis=abs(b-a)

for i in range(1,int(N**0.5)+1):
    if N%i==0:
        _a=i
        _b=N//i
        _dis=abs(_b-_a)
        if _dis<dis:
            a=_a
            b=_b
            dis=_dis

print((a-1+b-1))
# Original solution
N = int(eval(input()))
i = int(N**0.5)
while N%i!=0:
  i -= 1
print((i+N//i-2))

# Optimized solution
def solve():
    N = int(eval(input()))
    n = int(N**0.5)+1
    for i in range(n,0,-1):
        if N%i==0:
            ans = i+N//i-2
            break
    return ans
print((solve()))
# Original solution
N = int(eval(input()))
from collections import deque


def p_f(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


hoge = p_f(N)
DP = deque()
DP.append(1)

if len(hoge) == 1:
    print((hoge[0]-1))
else:
    Min = 10**12

    for i in range(len(hoge)):
        for j in range(len(DP)):
            x = DP[j]*hoge[i]
            DP.append(x)
            if (x + (N // x) - 2) < Min:
                Min = (x + (N // x) - 2)

    print(Min)

# 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


List = make_divisors(N)

if len(List) % 2 == 1:
    print((List[len(List) // 2] * 2 - 2))
else:
    print((List[len(List) // 2 - 1] + (List[len(List) // 2] - 2)))
# Original solution
n = int(eval(input()))

max_div_num = 1

for i in range(2, int(n**(1/2) + 1)):
    if n % i == 0:
        max_div_num = max(i, max_div_num)

x = max_div_num
y = n // max_div_num

print((x + y - 2))

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

max_div_num = 1

for i in range(2, int(n**(1/2) + 1)):
    if n % i == 0:
        max_div_num = i

x = max_div_num
y = n // max_div_num

print((x + y - 2))
# Original solution
N = int(eval(input()))


def dist(i, j):
    return i + j - 2


min = 10 ** 24
i = 1
while (i ** 2) <= N:
    if 0 == N % i:
        j = N // i
        d = dist(i, j)
        if min > d:
            min = d
    i += 1
print(d)


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

ans = 0
for i in range(math.ceil(math.sqrt(n) + 1))[:0:-1]:
    if 0 == n % i:
        ans = i
        break
ans_partner = n // ans
print((ans + ans_partner - 2))
# Original solution
from functools import reduce

def factorization(n):
    '''
    素因数分解の結果を返す
    例： n = 100 の時、[2, 2, 5, 5] 
    '''
    arr = []
    tmp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if tmp % i == 0:
            while tmp % i == 0:
                arr.append(i)
                tmp //= i
    if tmp != 1:
        arr.append(tmp)
    if arr == []:
        arr.append(n)
    return arr


def combination(l):
    res = []
    for i in range(1, 2**len(l)):
        tmp = []
        for j in range(len(l)):
            if (i >> j) &1 == 1:
                tmp.append(l[j])
        res.append(tmp)
    return res


def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]


def solve():
    N = int(eval(input()))
    F = factorization(N)
    ans = N - 1
    for c in get_unique_list(combination(F)):
        t = reduce(lambda x, y: x * y, c)
        ans = min(ans, N // t - 1 + t - 1)
    print(ans)

if __name__ == "__main__":
    solve()


# Optimized solution
def make_divisors(n):
    '''
    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 solve():
    N = int(eval(input()))
    D = make_divisors(N)
    ans = N - 1
    for d in D:
        ans = min(ans, N // d - 1 + d - 1)
    print(ans)

if __name__ == "__main__":
    solve()
# Original solution
import math
N = int(eval(input()))
for i in range(int(math.sqrt(N))):
    if N % (int(math.sqrt(N))-i) == 0:
        print((int(N/(int(math.sqrt(N))-i)+int(math.sqrt(N))-i-2)))
        break

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

# Optimized solution
n=int(eval(input()));print((min(i+n//i-2for i in range(1,int(n**.5)+1)if n%i<1)))
# Original solution
def dfs(n):
    table =[]
    i = 2
    while n >= i**2:
    # nのその数自身を除いた素因数は√n以下であることから。
        while n % i == 0:
            table.append(i)
            n /= i
        i += 1
    if n > 1:
        table.append(int(n))
# 最後に残った、最大の素因数をリストに入れる。
    return table

N = int(eval(input()))
f_list = dfs(N)
if len(f_list) == 1:
  print((f_list[0] - 1))
  exit()
elif len(f_list) == 2:
  s = 0
  for f in f_list:
    s += f
  print((s - 2))
  exit()
ans = float('inf')
for x in range(10**12):
  if x + 1 > N:
    break
  for y in range(10**12):
    if (x + 1) * (y + 1) > N:
      break
    if (x + 1) * (y + 1) == N:
      ans = min((x + y), ans)
print(ans)

# Optimized solution
N = int(eval(input()))
from math import sqrt
def get_divs(n):
  divs = []
  for i in range(1, int(sqrt(n)) + 1):
    if n % i == 0:
      divs.append((i, n // i))
  return divs

divs = get_divs(N)
ans = float('inf')
for x, y in divs:
  ans = min(ans, (x + y - 2))
print(ans)
# Original solution
import collections
import copy

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

x = int(eval(input()))
master_c = prime_factorize(x)
if len(master_c) == 1:
    print((x-1))
else:
    min_num = x-1
    for i in range(2,int(x/2)):
        if x % i == 0:
            num = int(i+(x/i)-2)
            if num < min_num:
                min_num = num
    print(min_num)

# Optimized solution
import math
x = int(eval(input()))
x_sqrt = int(math.sqrt(x))

min_num = x-1
for i in range(2,x_sqrt+2):
    if x % i == 0:
        num = i+int(x/i)-2
        if num < min_num:
            min_num = num
print(min_num)