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

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

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

-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))) +M = int(math.sqrt(N)) +for i in range(M): +    if N % (M - i) == 0: +        print((int(N / (M - i) + M - i - 2)))