import scala.annotation.tailrec

/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0011&lang=jp
  * Drawing Lots
  */
object Main {
  def main(args: Array[String]): Unit = {
    val w = io.StdIn.readInt()
    val n = io.StdIn.readInt()
    val hLines = Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).take(n)
      .map(_.split(",").map(_.toInt)).map { case Array(a, b) => (a, b) }
      .toList
    val vLines = 1 to w
    val playedVLines = playAmida(vLines, hLines)
    playedVLines.foreach(println)
  }

  @tailrec
  def playAmida(vLines: Seq[Int], hLines: Seq[(Int, Int)]): Seq[Int] = {
    hLines match {
      case Nil => vLines
      case hHead :: hTail =>
        val newVLines = vLines.zipWithIndex
          .map {
            case (_, i) if i == hHead._1 - 1 => vLines(hHead._2 - 1)
            case (_, i) if i == hHead._2 - 1 => vLines(hHead._1 - 1)
            case (e, _) => e
          }
        playAmida(newVLines, hTail)
    }
  }

}