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
let ans = f(n)
    .sorted()
    .first ?? 0

print(ans)
