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

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

-    if N / i == int(N / i): +    if N % i == 0: