fun main(args : Array<String>) {
    val n = readLine()!!.toLong()
    var min = (1..1000000.toLong())
        .filter { n % it  == 0L }
        .map { it + (n / it) - 2 }
        .min()
    println(min)
}
