function Main(n) {
  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);
			result.push({num:i, r:r});
		}
	}
	if (n > s) {
		result.push({num:n, r:1});
	}
  result.reverse();
  var P = 1;0
  var Q = 1;
for(var i = 0;i<result.length;i++){
  for(var j = 0;j<result[i].r;j++){
if(P<Q){
  P *= result[i].num;
}else{
  Q *= result[i].num;
}
  }
}
  console.log(P+Q-2);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));