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: Long): List[Long] = {
    (2L to Math.sqrt(n).toLong).find(n % _ == 0) match {
      case Some(d) => d :: toPrimes(n / d)
      case None => n :: Nil
    }
  }

  def findAll(n: Long): List[(Long, Long)] = {
    def inner(a: Long, b: Long, primes: List[Long]): List[(Long, Long)] = {
      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))
  }
}
