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));

	var r = 0;

	var result = Array();

	for (var i = 2;i <= s;i++) {

		if ((n % i) == 0) {

			r = 0; 

			do {

				r++; 

				n = n / i;

			} while ((n % i) == 0);

            for (var v = 0; v < r ; v++){
                sv.push(i);
            }
		}

	}

	if (n > s) {
		sv.push(n);
    }
    
    sv.reverse();

    var a=1
    var b = 1

    sv.forEach((vv) =>{
        if(a < b){
            a*=vv
        }else{
            b*=vv
        }
    })

    console.log(a+b-2)
});