import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val n = new BufferedReader(new InputStreamReader(System.in)).readLine().toLong

    System.out.println(
      findAll(n).minBy { case (a, b) =>
        a + b
      } match {
        case (a, b) => a + b - 2
      }
    )
  }

  def toPrimes(n: BigInt): List[BigInt] = {
    def inner(n: BigInt, d: BigInt, primes: List[BigInt]): List[BigInt] = {
      if (n % d == 0) {
        inner(n / d, 2, d :: primes)
      } else if (n < d * d) {
        n :: primes
      } else {
        inner(n, d + 1, primes)
      }
    }
    inner(n, 2, Nil)
  }

  def findAll(n: BigInt): List[(BigInt, BigInt)] = {
    def inner(a: BigInt, b: BigInt, primes: List[BigInt]): List[(BigInt, BigInt)] = {
      primes match {
        case prime :: tail =>
          val na = a / prime
          val nb = b * prime
          (a, b) :: inner(na, nb, tail)
        case Nil =>
          Nil
      }
    }

    inner(n, 1L, toPrimes(n))
  }
}
