function isPrime(n) {
    if (n < 2) {
        return false;
    }
    if (n === 2 || n === 3 || n === 5) {
        return true;
    }
    if (n % 2 === 0 || n % 3 === 0 || n % 5 === 0) {
        return false;
    }
    var prime = 7;
    var step = 4;
    var limit = Math.sqrt(n);
    while (prime <= limit) {
      if (n % prime === 0) return false;
      prime += step;
      step = 6 - step;
    }
    return true;
};

function Main(input) {
    var N = parseInt(input[0], 10);
    
    var sqrt = Math.sqrt(N);
    if (Number.isInteger(sqrt)) {
        console.log(sqrt * 2 - 2);
    } else if (isPrime(N)) {
        console.log(N - 1);
    } else {
        for (var i = Math.ceil(sqrt); i < N; i++) {
            if (N % i === 0) {
                return console.log(i + (N / i) - 2);
            }
        }
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));