def resolve():

    N, M = [int(i) for i in input().split()]

    path = [[] for _ in range(N)]

    for _ in range(M):

        A, B = [int(i) for i in input().split()]

        path[A - 1].append(B - 1)

        path[B - 1].append(A - 1)

    visited = [-1] * N

    que = [0]

    visited[0] = 0



    while que:

        v = que.pop(0)

        for nv in path[v]:

            if visited[nv] != -1:

                continue

            visited[nv] = v + 1

            que.append(nv)



    if -1 in visited:

        print("No")

    else:

        print("Yes")

        for i in range(N - 1):

            print((visited[i + 1]))





resolve()

def resolve():

    N, M = [int(i) for i in input().split()]

    AB = [[] for _ in range(N + 1)]

    AB[0] = [1]

    for _ in range(M):

        A, B = [int(i) for i in input().split()]

        AB[A].append(B)

        AB[B].append(A)

    from collections import deque

    dq = deque([1])

    ans = [-1] * (N + 1)

    while len(dq) > 0:

        p = dq.popleft()

        c = AB[p]

        for cc in c:

            if ans[cc] == -1:

                ans[cc] = p

                dq.append(cc)

    if -1 in ans[2:]:

        print("No")

        print(ans, file=sys.stderr)

    else:

        print("Yes")

        for a in ans[2:]:

            print(a)





resolve()

def resolve():
    N, M = [int(i) for i in input().split()]
    path = [[] for _ in range(N)]
    for _ in range(M):
        A, B = [int(i) for i in input().split()]
        path[A - 1].append(B - 1)
        path[B - 1].append(A - 1)
    visited = [-1] * N
    que = [0]
    visited[0] = 0
    while que:
        v = que.pop(0)
        for nv in path[v]:
            if visited[nv] != -1:
                continue
            visited[nv] = v + 1
            que.append(nv)
    if -1 in visited:
        print("No")
    else:
        print("Yes")
        for i in range(N - 1):
            print((visited[i + 1]))


resolve()

def resolve():
    N, M = [int(i) for i in input().split()]
    AB = [[] for _ in range(N + 1)]
    AB[0] = [1]
    for _ in range(M):
        A, B = [int(i) for i in input().split()]
        AB[A].append(B)
        AB[B].append(A)
    from collections import deque

    dq = deque([1])
    ans = [-1] * (N + 1)
    while len(dq) > 0:
        p = dq.popleft()
        c = AB[p]
        for cc in c:
            if ans[cc] == -1:
                ans[cc] = p
                dq.append(cc)
    if -1 in ans[2:]:
        print("No")
        print(ans, file=sys.stderr)
    else:
        print("Yes")
        for a in ans[2:]:
            print(a)


resolve()

-    path = [[] for _ in range(N)] +    AB = [[] for _ in range(N + 1)] +    AB[0] = [1] -        path[A - 1].append(B - 1) -        path[B - 1].append(A - 1) -    visited = [-1] * N -    que = [0] -    visited[0] = 0 -    while que: -        v = que.pop(0) -        for nv in path[v]: -            if visited[nv] != -1: -                continue -            visited[nv] = v + 1 -            que.append(nv) -    if -1 in visited: +        AB[A].append(B) +        AB[B].append(A) +    from collections import deque + +    dq = deque([1]) +    ans = [-1] * (N + 1) +    while len(dq) > 0: +        p = dq.popleft() +        c = AB[p] +        for cc in c: +            if ans[cc] == -1: +                ans[cc] = p +                dq.append(cc) +    if -1 in ans[2:]: +        print(ans, file=sys.stderr) -        for i in range(N - 1): -            print((visited[i + 1])) +        for a in ans[2:]: +            print(a)