function main(arg) {
	var num = parseInt(arg.replace(/\s/g,"").replace(/\r/g,""));
 
	var jougen = Math.sqrt(num)+10;
	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'));