object Main extends App {
  import scala.io.StdIn._
  val n = readInt()
  val pairs = Array.fill(n){
    val Array(f, t) = readLine.trim.split(' ').map(_.toInt)
    (f, t)
  }
  val result = pairs.map(p ⇒ makeFunc(p._1, p._2)).reduce(_ | _)
  println(result)
  def makeFunc(from: Int, to: Int): Token = {
    if (to == 0) 0
    else (0 until 32).collect{
      case digit if (to & (1 << digit)) != 0 ⇒ makeDigit(from, digit)
    }.reduce(_ | _)
  }
  def makeDigit(from: Int, digit: Int): Token = {
    digit match {
      case 0 if (from & 1) == 1 ⇒ X&1
      case 0 if (from & 1) == 0 ⇒ ~X&1
      case _ if (from & (1 << digit)) != 0 ⇒ (X&(1<<digit)) & makeDigit(from, digit - 1)*2
      case _ ⇒ (~X&(1<<digit)) & makeDigit(from, digit - 1) * 2
    }
  }
  sealed trait Token {
    def &(that: Token): Token = Expression(this, "&", that)
    def |(that: Token): Token = Expression(this, "|", that)
    def ^(that: Token): Token = Expression(this, "^", that)
    def +(that: Token): Token = Expression(this, "+", that)
    def -(that: Token): Token = Expression(this, "-", that)
    def *(that: Token): Token = Expression(this, "*", that)
    def unary_~(): Token = Negative(this)
    def apply(x: Int): Int
  }
  case object X extends Token {
    override def toString: String = "x"
    override def apply(x: Int): Int = x
  }
  implicit class Number(value: Int) extends Token {
    override def toString: String = value.toString
    override def apply(x: Int): Int = value
  }
  case class Expression(left: Token, op: String, right: Token) extends Token {
    override def toString: String = s"($left$op$right)"
    override def apply(x: Int): Int = {
      op match {
        case "&" ⇒ left(x) & right(x)
        case "|" ⇒ left(x) | right(x)
        case "^" ⇒ left(x) ^ right(x)
        case "+" ⇒ left(x) + right(x)
        case "-" ⇒ left(x) - right(x)
        case "*" ⇒ left(x) * right(x)
      }
    }
  }
  case class Negative(token: Token) extends Token {
    override def toString: String = s"(~$token)"
    override def apply(x: Int): Int = ~token(x)
  }
}
