import java.util.Scanner

import scala.collection.mutable

object Main extends App {
  val sc = new Scanner(System.in)
  val N, M = sc.nextInt
  val AB = Array.fill(M, 2)(sc.nextInt)

  val G = (AB ++ AB.map(_.reverse)).groupBy(_(0)).map(x => { x._1 -> x._2.map(_(1)) })

  val X = Array.fill(N)(false)
  val Y = Array.fill(N)(-1)

  def BFS(x: Int): Unit = {
    val Q = new mutable.Queue[Array[Int]]()
    X(x - 1) = true
    Y(x - 1) = 0
    Q += Array(x, 0)
    while (Q.nonEmpty) {
      val v = Q.dequeue
      X(v(0) - 1) = true
      G(v(0)).foreach(i => {
        if (!X(i - 1)) {
          X(i - 1) = true
          Y(i - 1) = v(0)
          Q += Array(i, v(1) + 1)
        }
      })
    }
  }
  BFS(1)

  println("Yes")
  Y.tail.foreach(println)
}
