// 🐋💭  Walk on Multiplication Table
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDouble() -> Double {
    return Double(readLine()!)!
}


func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

func main() {
    let n = readInt()
    let sqrtN = Int(sqrt((Double(n))))
    
    var ans = n - 1
    for i in (1..<sqrtN-1) {
        ans = min(ans, (n % i - 1) + (i - 1))
    }
    print(ans)
}
main()
