import kotlin.math.sqrt


fun main (args:Array<String>){
    val box = readLine()!!.toLong()
//    var boxIList : MutableSet<Int> = mutableSetOf()
//    var boxJList : MutableSet<Int> = mutableSetOf()
    var boxList : MutableSet<Long> = mutableSetOf()
    val boxSqrt = sqrt(box.toDouble()).toLong()
    for(i in 1L..boxSqrt){
            if (box % i == 0L) {
                boxList.add((i + (box/i-2)).toLong())
           }
    }
//    if(boxList.size % 2 == 0){
//        print(boxList.elementAt(boxList.size/2) + boxList.elementAt(boxList.size/2-1) -2)
//        return
//    }
//    print(boxList.elementAt(boxList.size / 2 * 2 -2))
//    println(boxIList)
//    println(boxJList)
    println(boxList.min())
}
