object Main extends App {
  var list = List[Int](1)
  (2 to 999).foreach { i =>
    list :+= (i + list.last)
  }

  val Array(a, b) = scala.io.StdIn.readLine.split(" ").map(_.toInt)

  (1 to 1000000000).foreach { i =>
    if(list.contains(a + i) && list.contains(b + i)) {
      println(i)
      System.exit(0)
    }
  }
}