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

    var res = N
    var k = 1L

    while(k * k <= N) {
        if (N % k == 0L) {
            res = k + N / k - 2
        }
        k++
    }

    println(res)
}
