object Main extends App {
    val N = readLong
    val max = Math.sqrt(N)
    def calc(i:Long, currentAns:Long):Long =  {
        if(i > max) {
            currentAns
        } else {
            var ans = currentAns
            if(N % i == 0) {
                val sum = N / i + i
                if(sum < currentAns) {
					ans = sum
                }
            }
            calc(i + 1, ans)
        }
    }
    var ans = calc(1, N + 1)
    println(ans - 2)        

}