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