function Main(input){
    input = parseInt(input);
    var i = Math.sqrt(input);

    var array = [];
    for (var index = 1; index <= i; index++) {
        if(input%index == 0){
            array.push(input/index+index);
        }
    }
    console.log(array.reduce((a,b)=>Math.min(a,b))-2);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 