object Main {
  def main(args: Array[String]) = {
  val N = io.StdIn.readLong
  var sum = 0L
  var k = 1
  while(true) {
    sum += k
    if(sum % N == 0) {
      println(k)
      System.exit(0)
    }
    k += 1
  }
  }
}




