fun main(args: Array<String>) {
  println(questionC(readLine()!!.toLong()))
}
 
fun questionC(n: Long): Long {
    var min = Long.MIN_VALUE

    if (n in 2L..Long.MAX_VALUE) {
        val table = Math.sqrt(n.toDouble()).toLong()
        (1..table).forEach {
            if (n % it != 0L) return@forEach

            min = Math.min(Long.MAX_VALUE, it + n / it - 2)
        }
    }

    return min
}