CodeEff/ECCO huggingface dataset:
# Original solution
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

if len(prime_factorize(n)) == 1:
  print((n - 1))
  exit()

ret = None
min_r = n
for x in range(1, int( n / 2)):
  q, mod = divmod(n, x)
  _min_r = (2 * x - 2) + (q - x)
  if mod == 0 and min_r > _min_r:
    min_r = _min_r
    ret = (x, q)

print(min_r)

# Optimized solution
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

if len(prime_factorize(n)) == 1:
  print((n - 1))
  exit()

ret = None
min_r = n
for x in range(2, int( n / 2)):
  q, mod = divmod(n, x)
  _min_r = (2 * x - 2) + (q - x)
  if mod == 0 and min_r > _min_r:
    min_r = _min_r
    ret = (x, q)
  
  if x > q:
    break

print(min_r)
# Original solution
import math
n = int(eval(input()))

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


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

ans = float("inf")
for i in range(1, int(math.sqrt(n))+1):
    if n%i == 0:
        ans = min(ans, i-1+(n//i)-1)

print(ans)
# Original solution
num = int(eval(input()))
minimam = 10**12
for i in range(1,10**6+1):
    q, mod = divmod(num, i)
    distance = q + i -2
    if mod == 0 and minimam > distance:
        minimam = distance
print(minimam)

# Optimized solution
import math
input_num = int(eval(input()))
num_sqrt = int(math.sqrt(input_num))+1

minimam = input_num
for i in range(1,num_sqrt+1):
    q, mod = divmod(input_num, i)
    distance = q + i -2
    if mod == 0 and minimam > distance:
        minimam = distance
print(minimam)
# Original solution
import math
input_num = int(eval(input()))
num_sqrt = int(math.sqrt(input_num))

minimam = input_num
for i in range(num_sqrt+1,0,-1):
    q, mod = divmod(input_num, i)
    distance = q + i -2
    if mod == 0 and minimam > distance:
        minimam = distance
print(minimam)

# Optimized solution
import math
def main1():
    input_num = int(eval(input()))
    num_sqrt = int(math.sqrt(input_num))

    minimam = input_num
    for i in range(num_sqrt+1,0,-1):
        q, mod = divmod(input_num, i)
        if mod == 0:
            distance = q + i -2
            if minimam > distance:
                minimam = distance
    print(minimam)
main1()
# Original solution
N = int(eval(input()))
from math import sqrt
ab_add = []
for i in range(1, int(sqrt(N)) + 1):
    if N % i == 0:
        ab_add.append(i + (N // i) - 2)
print((min(ab_add)))


# 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 + n // i) - 2)
            if i != n // i:
                divisors.append((n // i + i) - 2)

    divisors.sort()
    return divisors


div = make_divisors(N)
print((min(div)))
# Original solution
import math
N = int(eval(input()))
for i in range(int(math.sqrt(N)), 0, -1):
  if N / i == int(N / i):
      print((int(N / i + i - 2)))
      exit()

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

A=int(math.sqrt(N))
a=1
b=1
for i in range(1, A+1):
  if N%i==0:
    a=i
    b=N/i
print((int(a+b-2)))

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

M=int(sqrt(N))
a=0
for i in range(M,0,-1):
  if N%i==0:
    a=i
    break
b=int(N//i)
print((a+b-2))
# Original solution
from collections import deque
pf={}
res = []
m= int(eval(input()))
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        res.append(i)
        m//=i
if m>1:
    res.append(m)
    pf[m]=1

cgg = deque()
for index in range(2**len(res)):

    s1 = 1
    s2 = 1
    for j in range(len(res)):
        if (index >> j & 1) == 1:
            s1 = s1 * res[j]
        else:
            s2 = s2 * res[j]

    cgg.append(s1-1 + s2 - 1)


print((min(cgg)))




# Optimized solution
import math

N = 10000000019
N = 50
N = 10
N = int(eval(input()))

result = []
for i in range(1, math.ceil(math.sqrt(N))+1):
    if N % i == 0:
        result.append((i + (N // i)) - 2)

print((min(result)))
# Original solution
def make_divisors(n):
    """自然数nの約数を列挙したリストを出力する
    計算量: O(sqrt(N))
    入出力例: 12 -> [1, 2, 3, 4, 6, 12]
    """
    divisors = []
    for k in range(1, int(n**0.5) + 1):
        if n % k == 0:
            divisors.append(k)
            if k != n // k:
                divisors.append(n // k)
    divisors = sorted(divisors)
    return divisors


n = int(eval(input()))
ans = make_divisors(n)
res = 10**18
for i in range(len(ans)):
    tmp = ans[i] + n // ans[i] - 2
    res = min(tmp, res)
print(res)

# Optimized solution
def make_divisors(n: int) -> list:
    """自然数nの約数を列挙したリストを出力する
    計算量: O(sqrt(N))
    入出力例: 12 -> [1, 2, 3, 4, 6, 12]
    """
    divisors = []
    for k in range(1, int(n ** 0.5) + 1):
        if n % k == 0:
            divisors.append(k)
            if k != n // k:
                divisors.append(n // k)
    divisors = sorted(divisors)
    return divisors


n = int(eval(input()))
div = make_divisors(n)
ans = 10 ** 18
for i in div:
    ans = min(ans, i + n // i - 2)
print(ans)
# Original solution
def divisor(n):
    # 約数
    return [[i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0]


def main():
    N = int(eval(input()))
    print((divisor(N)[-1][0] + divisor(N)[-1][1] - 2))
    return


main()


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


def main():
    N = int(eval(input()))
    rslt = divisor(N)
    print((rslt[-1][0] + rslt[-1][1] - 2))
    return


main()
# Original solution
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

a=divisor(n)
a.sort()

c=[]
for i in range(len(a)//2+1):
    d=a[i]-1+a[-i-1]-1
    c.append(d)

print((min(c)))

# Optimized solution
import sys

n=int(eval(input()))

c=[]

for i in range(2,int(n**(1/2))+1):
    if n%i==0:
        c.append(i+n//i-2)

if len(c)==0:
    print((n-1))
    sys.exit()
    
print((min(c)))
# Original solution
N = int(eval(input()))
ans = 10 ** 19
for i in range(1, int(N**.5) + 1):
  if N % i == 0:
    ans = min(ans, i + N // i -2)
print(ans)

# Optimized solution
n = int(eval(input()))
for i in range(int(n**.5) + 1, 0, -1):
  if n % i == 0:
    ans = n // i + i - 2
    print(ans)
    exit()
# Original solution
# C - Walk on Multiplication Table
# https://atcoder.jp/contests/abc144/tasks/abc144_c

n = int(eval(input()))

ans = 10 ** 12
for i in range(1, 10 ** 6 + 1):
  if n % i == 0:
    ans = min(ans, n // i + i)

print((ans - 2))

# Optimized solution
# C - Walk on Multiplication Table
# https://atcoder.jp/contests/abc144/tasks/abc144_c

n = int(eval(input()))

ans = n
for i in range(1, int(n**.5) + 2):
  if n % i == 0:
    ans = min(ans, n // i + i - 2)

print(ans)
# Original solution
import math

INF = 1e12
n = int(eval(input()))
cnt = INF
m = math.sqrt(n)

for i in range(1, math.ceil(m) + 1):
  if n % i == 0:
    j = n // i
    cnt = min(cnt, i + j - 2)
  else:
    continue

print(cnt)

# Optimized solution
from math import ceil

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

n = int(eval(input()))
divs = divisors(n)
ans = 10 ** 12
divs.sort()
for i in range(ceil(len(divs) / 2)):
    a = divs[i]
    b = divs[(i + 1) * (-1)]
    ans = min(ans, (a - 1) + (b - 1))

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

x = int(N ** 0.5)

for i in range(x):
    if N % x == 0:
        y = N // x
        break
    x -= 1

ans = x + y - 2

print(ans)


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

x = int(N ** 0.5)

for i in range(x, 0, -1):
    if N % i == 0:
        y = N // i
        break

ans = N // y + y - 2

print(ans)
# Original 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))
            if i != n // i:
                divisors.append((n//i,i))

    # divisors.sort()
    return divisors
N=int(eval(input()))
div=make_divisors(N)
ans=float("inf")
for x, y in div:
  ans=min(ans,(x-1)+(y-1))
print(ans)

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


def divisors(n):
    ret = set()
    for i in range(1, int(n**(0.5))+1):
        if n % i == 0:
            ret.add(i)

    return(ret)


ans = N-1
for x in divisors(N):
    ans = min(ans, x-1+(N//x)-1)

print(ans)
# Original solution
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

def solve():
    n = int(eval(input()))
    if is_prime(n):
        print((n-1))
        return
    half = int(math.sqrt(n))
    for i in range(half, n):
        if n % i == 0:
            a = i
            b = n // i
            print((a + b - 2))
            return
    return 

if __name__ == '__main__':
    solve()

# Optimized solution
import math

def is_prime(n):
    if n == 1: return (False, -1)

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

    return (True, 1)

def solve():
    n = int(eval(input()))
    p, k = is_prime(n)
    if p:
        print((n-1))
        return
    l = n // k
    print((k + l - 2))
    return
    '''
    half = int(math.sqrt(n))
    for i in range(half, n):
        if n % i == 0:
            a = i
            b = n // i
            print(a + b - 2)
            return
    return 
    '''

if __name__ == '__main__':
    solve()
# Original solution
n = int(eval(input()))
c = max([i for i in range(1,int(n**0.5+1)) if n%i==0])
print((c+n//c-2))

# Optimized solution
a = int(eval(input()))
c = [j for j in range(1,int(a**0.5)+1) if a%j==0]
if c:
    print(((max(c)-1) + (a//max(c)-1)))
else:
    print((a-1))
# Original solution
from functools import reduce
from copy import copy

N = 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)

    if temp!=1:
        arr.append(temp)

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

    return arr

facts = factorization(N)

def dfs(arr, depth):
    if depth == len(facts):
        left = reduce(lambda a,b: a * b, [f for i, f in enumerate(facts) if arr[i]], 1)
        right = reduce(lambda a, b: a * b, [f for i, f in enumerate(facts) if not arr[i]], 1)
        return left + right
    left_arr = copy(arr)
    left_arr.append(True)
    right_arr = copy(arr)
    right_arr.append(False)
    left = dfs(left_arr, depth+1)
    right = dfs(right_arr, depth + 1)
    return min(left, right)
print((dfs([], 0) - 2))

# Optimized solution
N = int(eval(input()))
answer = 1000000000000
for i in range(1, int(N ** (0.5)) + 2):
    if N % i == 0:
        j = N // i
        if i + j - 2 < answer:
            answer = i + j - 2
print(answer)
# Original solution
N = int(eval(input()))

a, b = 1, N
for n in range(2,N):
    if n*n == N:
        a = b = n
        break
    elif n*n > N:
        break
    elif N%n == 0:
        a, b = n, N//n

print((a+b-2))

# Optimized solution
N=int(eval(input()))
ans = 10**12
for n in range(1,int(N**0.5)+1):
    if N%n==0:
        ans = min(ans, n + N//n - 2)
print(ans)
# Original solution
n=int(eval(input()))
num=int(n**0.5)+1
mini=float('inf')
for k in range(1,num+1):
    i=k
    j=0
    if n%i==0:
        j=n//i

    if j!=0 and mini>=i+j-2:
        mini=i+j-2

print(mini)


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

ans=10**12
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        ans=min(ans,i+n//i-2)
print(ans)
# Original solution
import math

N = int(eval(input()))

# n = p * q → p or q <= n**(1/2)
# because p and q > n**(1/2) → p * q > n

divisor = []
for i in range(1 , math.floor(N**(1/2))+1):
    if N % i == 0:
        divisor.append(i)

distance = []
for j in range(int(len(divisor))):
    M = (N / int(divisor[j])) + int(divisor[j])
    distance.append(M)

if int(len(divisor)) == 1:
    print((N-1))
else:
    print((math.floor(min(distance))-2))

# Optimized solution
n = int(eval(input()))
ans = 10**12

for i in range(1,int((n**0.5))+1):
    if n % i == 0:
        j = n // i
        dis = i + j - 2
        ans = min(ans,dis)
        
print(ans)
# Original solution
def enum_div_pairs(n):
    res = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            res.append((i, n // i))
            if i != n // i:
                res.append((n // i, i))
    return res


pairs = enum_div_pairs(int(eval(input())))
print((min(i + j - 2 for i, j in pairs)))


# Optimized solution
def get_nearest_div_pair(n):
    for i in range(int(n ** 0.5), 0, -1):
        if n % i != 0:
            continue
        return i + n // i - 2


print((get_nearest_div_pair(int(eval(input())))))
# 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

l = factorize(n)


import itertools
c = list(itertools.product(list(range(2)), repeat=len(l)))
#print(c)

flag = False
k = 10**15
for i in range((len(c)+1)//2):
    a = 1
    b = 1
    for j in range(len(c[i])):
        if c[i][j] == 0:
            a *= l[j]
        else:
            b *= l[j]
    k = min(k, a+b)
    if a == b:
        break
    

print((k-2))


# Optimized solution
#%%
n = int(eval(input()))
a = 10**15


x = int(n**0.5)
x += 1
for i in range(x, 1, -1):
    if n%i == 0:
        a = i
        b = n//i
        break
#print(a, b)

if a == 10**15:
    print((n-1))
else:
    print((a+b-2))
# Original solution
import math 

N = int(eval(input()))
lst =[]
#N = a*bとする。　ここで、a<=bが成り立つ。
#√a　の全探索
length= math.ceil(math.sqrt(N))
for i in range(length):
    if(N %(i+1) == 0):
        lst.append(i+1)
a = max(lst)
b = round(N/a)
ans = a+b -2
print(ans)

# Optimized solution
import math 

n = int(eval(input()))
a=0
b=0
root_n  = math.sqrt(n)
#繰り上げ
root_n = math.ceil(root_n)
yakusuu =[]
for i in range(1,root_n+1):
    if(n%i == 0):
        yakusuu.append(i)
a = max(yakusuu)
b = n / a
print((int(a+b-2)))
# Original solution
import itertools
from functools import reduce
from operator import mul


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

N = int(eval(input()))
factors = trial_division(N)

if len(factors) == 1:
  print((factors[0]-1))
else:
  res = N
  cumsum = reduce(mul, factors)
  for i in range(len(factors)//2):
    for comb in itertools.combinations(factors, i+1):
      a = reduce(mul, comb)
      b = cumsum // a
      if a+b-2 < res:
        res = a+b-2
  print(res)


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

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

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

a = [1, n]

for i in range(1, int(n**0.5)+1):
    j = n // i
    if n % i == 0 and a[0] + a[1] > i + j:
        a = [i, j]

print((a[0] - 1 + a[1] - 1))

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

#(1,1)から一番長く移動しないといけないのは(1,n)の時
ans = n - 1

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

print(ans)
# Original 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)

    # divisors.sort()
    return divisors
  
n = int(eval(input()))
d = make_divisors(n)
d.sort()
a = []
for i in range(len(d)-1):
  if d[i]**2==n:
    a.append([d[i], d[i]])
    break
  for j in range(i+1, len(d)):
    if d[i] * d[j] == n:
      a.append([d[i], d[j]])
      break
m = n
ind = 0
for i in a:
  if abs(i[0]-i[1]) < m:
    m = abs(i[0]-i[1])
    ind = a.index(i)

print((a[ind][0]+a[ind][1]-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
  
n = int(eval(input()))
d = make_divisors(n)
d.sort()
a = []
for i in range(len(d)-1):
  b = n // d[i]
  if b == d[i]:
    a.append([d[i], d[i]])
    break
  for j in range(i+1, len(d)):
    if b == d[j]:
      a.append([d[i], d[j]])
      break
m = n
ind = 0
for i in a:
  if abs(i[0]-i[1]) < m:
    m = abs(i[0]-i[1])
    ind = a.index(i)

print((a[ind][0]+a[ind][1]-2))
# Original solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

# Factoring by trial split
def getPrimeList(n):
  l=[]
  t=int(math.sqrt(n))+1
  
  for a in range(2,t):
    while n%a==0:
      n//=a
      l.append(a)
  
  if n!=1:
    l.append(n)
  
  return l

def main():
  n=I()

  a=getPrimeList(n)

  l=[]
  b=len(bin(1<<len(a)))-3
  for i in range(1<<len(a)):
    l.append(str(bin(i))[2:].zfill(b))
  
  ans=inf
  for x in l:
    _a=_b=1
    for i,y in enumerate(list(x)):
      if y=='0':
        _a*=a[i]
      else:
        _b*=a[i]
    ans=min(ans,_a+_b-2)

  return ans

# main()
print((main()))


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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

# Factoring by trial split
def getPrimeList(n):
  l=[]
  t=int(math.sqrt(n))+1
  
  for a in range(2,t):
    while n%a==0:
      n//=a
      l.append(a)
  
  if n!=1:
    l.append(n)
  
  return l

def main():
  n=I()

  a=getPrimeList(n)

  # l=[]
  # b=len(bin(1<<len(a)))-3
  # for i in range(1<<len(a)):
  #   l.append(str(bin(i))[2:].zfill(b))
  
  # ans=inf
  # for x in l:
  #   _a=_b=1
  #   for i,y in enumerate(list(x)):
  #     if y=='0':
  #       _a*=a[i]
  #     else:
  #       _b*=a[i]
  #   ans=min(ans,_a+_b-2)

  # return ans

  ans=inf
  b=len(a)
  for i in range(2**b):
    _a=_b=1
    for j in range(b):
      if ((i >> j) & 1):
        _a*=a[j]
      else:
        _b*=a[j]
    ans=min(ans,_a+_b-2)
  return ans

# main()
print((main()))
# Original solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

# Factoring by trial split
def getPrimeList(n):
  l=[]
  t=int(math.sqrt(n))+1
  
  for a in range(2,t):
    while n%a==0:
      n//=a
      l.append(a)
  
  if n!=1:
    l.append(n)
  
  return l

def main():
  n=I()
  a=getPrimeList(n)

  ans=inf
  b=len(a)
  for i in range(2**b//2):
    _a=_b=1
    for j,x in enumerate(a):
      if ((i>>j)&1):
        _a*=x
      else:
        _b*=x
    ans=min(ans,_a+_b-2)
  return ans

# main()
print((main()))


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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  n=I()

  ans=inf
  for x in range(1,int(math.sqrt(n))+1):
    if n%x==0:
      ans=min(ans,x+n//x-2)
  return ans

# main()
print((main()))
# Original solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  n=I()

  ans=inf
  for i in range(1,int(math.sqrt(n))+1):
    if n%i==0:
      ans=min(ans,i+n//i-2)
  return ans

# main()
print((main()))


# Optimized solution
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  n=I()
  ans=inf
  for i in range(1,int(math.sqrt(n))+1):
    if n%i==0:
      ans=min(ans,i+n//i-2)
  return ans

# main()
print((main()))
# Original 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)

    # divisors.sort()
    return divisors

num = int(eval(input()))
yaku = make_divisors(num)
ans = float("inf")
for i in yaku:
    for j in yaku:
        if i*j==num:
            ans=min(ans,i+j-2)
print(ans)

# Optimized solution
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(int(i+n/i-2))
    return divisors
ans = float("inf")
for i in make_divisors(int(eval(input()))):
    
    ans = min(ans,i)
print(ans)
# Original solution
n=int(eval(input()))
a=[]
ans=1e12
l=int(n**0.5)+2
for i in range(1,l):
  if i in a:
    continue
  elif n%i==0:
    a.append(i)
    a.append(n//i)
    ans=min(ans,(i+n//i-2))
print(ans) 

# Optimized solution
n=int(eval(input()))
a=[]
ans=1e12
l=int(n**0.5)+2
for i in range(1,l):
  if n%i==0 and i not in a:
    a.append(i)
    a.append(n//i)
    ans=min(ans,(i+n//i-2))
print(ans)
# Original solution
si = lambda: eval(input())
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
snm = lambda: list(map(str, input().split()))
nl = lambda: list(map(int, input().split()))

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


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