object Main extends App {
  val w = readInt
  val n = readInt
  val initList = (1 to w)
  (1 to n)
    .map(_ => readLine.split(",").map(_.toInt - 1))
    .foldLeft(initList: Seq[Int]){ case (acc, Array(x, y)) =>
      val first = acc.take(x)
      val second = acc.slice(x + 1, y)
      val third = acc.drop(y + 1)
      first ++ Seq(acc(y)) ++ second ++ Seq(acc(x)) ++ third
    }
    .foreach(println)
}

