"use strict";

const getAllFactorsFor = num => {
    let results = [], i;

    for(i=2; i*i<=num; i++) {
        while((num % i) === 0) {
          results.push(i);

          num /= i;
        }
    }

    if(num !== 1) {
      results.push(num);
    }

    return results;
}

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    
    let list = getAllFactorsFor(N);
    let temp = [];
    
    if(N < 4) {
    for(let i=1; i<N; i++) {
        if(N % i === 0) {
            temp.push((parseInt(i) + (N / i)) - 2);
        }
    }
    
    } else {
    for(let i=1; i<N; i++) {
        if(N % list[i] === 0) {
            temp.push((parseInt(list[i]) + (N / list[i])) - 2);
        }
    }
    }

    console.log(Math.min(...temp));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));
