"use strict";

function divisor(num) {
  let curDiv = 1;
  let divi = num;
  let i = num % 2 === 0 ? 2 : 3;
  if (num % 2 !== 0 && num % 3 !== 0) {
    return curDiv;
  }
  while (i < divi) {
    if (num % i === 0) {
      curDiv = i;
      divi = num / curDiv;
    }
    i += 2;
  }
  return curDiv;
}

function main(input) {
  input = parseInt(input.split("\n")[0]);
  let divis = divisor(input);
  console.log(divis - 1 + input / divis - 1);
}

main(require("fs").readFileSync("/dev/stdin", "UTF-8"));
