process.stdin.resume();
process.stdin.setEncoding('utf8');

var sv = []

var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', (line) => {
    var n = line
    var s = Math.floor(Math.sqrt(n));
    for(;;s--){
        if((n % s)=== 0){
            console.log(s + (n / s) - 2);
            return
        }
    }
});