object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    var n = sc.nextLong
    var a, b = 1L
    for(i <- 2 to Math.sqrt(n).toInt+1 if n%i == 0) {
      while(n%i ==0) {
        n = n / i
        if (a < b) {
          a = a*i
        } else {
          b = b*i
        }
      }
    }
    if (n != 1) {
      a = n
    }
    println((a-1)+(b-1))
  }
}
