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(
      findMinimum(n) match {
        case (a, b) => a+b-2
      }
    )
  }

  def toPrimes(n: Long): List[Long] = {
    (2 to Math.sqrt(n).toInt).find(n % _ == 0) match {
      case Some(d) => d :: toPrimes(n / d)
      case None => n :: Nil
    }
  }

  def findMinimum(n: Long): (Long, Long) = {
    def inner(a: Long, b: Long, primes: List[Long]): (Long, Long) = {
      primes match {
        case prime :: tail =>
          val na = a / prime
          val nb = b * prime
          if (a + b < na + nb) {
            (a, b)
          } else {
            inner(na, nb, tail)
          }
        case Nil =>
          (a, b)
      }
    }
    inner(n, 1, toPrimes(n))
  }
}
