fun main(args: Array<String>) {
    val n = readLine()!!.toLong()

    // 約数のList
    fun divisor(value: Long): List<Long> {
        val max = Math.sqrt(value.toDouble()).toLong()
        return (1..max)
            .filter { value % it == 0L }
            .map { listOf(it, value / it) }
            .flatten()
            .sorted()
    }

    divisor(n).map {
        n / it + it - 2
    }.min().let(::println)
}


