fun main(args: Array<String>) {
  val (N) = readLine()!!.split(" ").map { it.toLong() }
  val sqrtN = Math.sqrt(N.toDouble()).toLong() + 1
  var a = 1L
  for (i in 2..sqrtN) {
    if (N % i == 0L) a = i
  }
  val b = N / a
  println(a + b - 2)
}

