const main = (input) => {
  const num = Number(input);
  var flag = true;
  var moveNumXArray = [];
  var moveNumYArray = [];
  
  for(var i = 2; i < num; i++){
    if(num % i === 0) {
      moveNumXArray.push(i - 1);
      moveNumYArray.push(num / i - 1);
      flag = false;
    }
  }
  
  if(flag){
    minMoveValue = num - 1;
  }else{
    var minMoveValue = num;
    for(var k=0; k < moveNumXArray.length; k++){
      if(minMoveValue > moveNumXArray[k] + moveNumYArray[k])
        minMoveValue = moveNumXArray[k] + moveNumYArray[k];
    }
  }
  console.log(minMoveValue);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));