n = int(eval(input()))

r = int(n**.5)

for i in range(r):

  if n % (r-i) == 0:

    print(( (r-i) + n//(r-i) - 2 ))

    break
n = int(eval(input()))

s = int(n**.5)

for i in range(s):

  if n % (s-i) == 0:

    print(((s-i) + n // (s-i) - 2))

    break
n = int(eval(input()))
r = int(n**0.5)
for i in range(r):
    if n % (r - i) == 0:
        print(((r - i) + n // (r - i) - 2))
        break

n = int(eval(input()))
s = int(n**0.5)
for i in range(s):
    if n % (s - i) == 0:
        print(((s - i) + n // (s - i) - 2))
        break

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