    function main(arg) {
        var num = parseInt(arg);
     
        var jougen = Math.sqrt(num)+1;
        var kyori = num - 1;
     
        for(i=2;i<jougen;i++){
        	if(num%i===0){
        	    var hikaku = i + num/i - 2;
        		if(hikaku<kyori){
        			kyori = hikaku;
        		}
        	}
        }
        console.log(kyori);
    }
    main(require('fs').readFileSync('/dev/stdin', 'utf8'));