import java.io.{BufferedReader, InputStreamReader}

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

    System.out.println(
      (sqrt_of_n to 2 by -1).find(d => n % d == 0) match {
        case Some(d) => n / d + d - 2L
        case None => n + 1L - 2L
      }
    )
  }
}
