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

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

-        max_div_num = max(i, max_div_num) +        max_div_num = i