object main{ object Solver extends Solvable with InputReader{ def solve(){ val n = getInt() - 1 val m = getInt() val a = Array(0, 0, 0) a(n) = 1 for(_ <- 1 to m){ val p = getInt() - 1 val q = getInt() - 1 val t = a(p); a(p) = a(q); a(q) = t } println(a.indexOf(1) + 1) } } // TEMPLATE ------------------------ def main(args: Array[String]){ Solver.solve() } trait Solvable{ def solve() } trait InputReader{ import java.io._ import java.util._ protected val stream = System.in private val reader = new BufferedReader(new InputStreamReader(stream)) private var tokenizer = new StringTokenizer(reader.readLine()) def getStr(): String = { while(!tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(reader.readLine()) tokenizer.nextToken() } def getInt(): Int = getStr().toInt def getLong(): Long = getStr().toLong def getDouble(): Double = getStr().toDouble } }