input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
N = lines.shift() * 1

_dividers = function(n) {
  var arr = []
  for (var i = 1; i*i <= n; i++) {
     if (n % i === 0) {
       arr.push(i)
       if ( i != n / i) {
         arr.push(n / i)
       }
     }
  }
  return arr.sort((a, b) => a - b)
}

ds = _dividers(N)

min = N
for (i=0; i <ds.length-i; i++) {
    for (j=i; j <ds.length; j++) {
        if (N == ds[i] * ds[j]) {
            if (min > ds[i] - 1 + ds[j] - 1) {
                min = ds[i] - 1 + ds[j] - 1
            }         
        }
    }
}
console.log(min)
