import Glibc

func f(n: Int) -> [Int] {
    let sqrtn = Int(sqrt(Double(n)))
    return (1..<sqrtn)
        .filter {n % $0 == 0}
        .map {$0 + (n / $0) - 2}
}

//let n = 10000000019
let n = Int(readLine() ?? "0") ?? 1
var tmp = f(n)
tmp.sort()
var ans = tmp.first ?? 0

print(ans)
