
fun main(args: Array<String>) {
    val x = readLine()!!.toLong()
    var best = x - 1L
    (1L..1000003L).forEach { a ->
        if (x % a == 0L) {
            val b = x /a
            val c = a - (if (a == 1L) 0L else 1L) +
                    b - (if (b == 1L) 0L else 1L)
            best = Math.min(best, c)
        }
    }

    println(best)
}
