function pf(n) {
    var result = [];

    if (n === 1) {
        return [1];
    }

    var init = 2;

    while (n !== 1) {
        var i = init;
        while (i < Number.MAX_SAFE_INTEGER) {
            if (n % i == 0) {
                result.push(i)
                n /= i;
                break;
            }
            i++;
        }
        init = i;
    }
    return result;
}

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);
    
    if (isPrime(N)) {
        console.log(N - 1);
    } else {
        var list = pf(N);
        var max = list[list.length - 1];
        console.log(max + (N / max) - 2);
    }
}

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