fun main(args: Array<String>){
  val n = readLine()!!.toLong()
  
  val sqrt = Math.sqrt(n.toDouble()).toInt()
  
  for( i in sqrt downTo 1 )
    if( n % i.toLong() == 0L ){
      println( i + n/i - 2 )
      break
    }
}
