"use strict";
const main = arg => {
  let num1, num2;
  let ans = 0;
  let info = arg * 1;
  for(let i = 2; i < Math.floor(Math.sqrt(info)); i++){
    if(info % i == 0){
      ans = i + (info / i) - 2;
    }
  }
  if(ans == 0){
  	ans = info - 1;
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
