import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextLong()

  val ans = mutableListOf<Long>()
  val sqrtN = Math.sqrt(n.toDouble())
  for (i in 2L .. sqrtN.toLong()) {
    if (n % i != 0L) {
      continue
    }
    val y = n / i
    val tmp = (i - 1L) + (y - 1L)
    ans.add(tmp)
  }
  ans.add(n - 1L)

  println(ans.min())
}