N, M = map(int, input().split())
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))

list = [0] * (N+1)

saitan = [1]
for _ in range(M):
    next = []
    for i in range(len(AB)):
        if AB[i][0] in saitan:
            if list[AB[i][1]] == 0:
                list[AB[i][1]] = AB[i][0]
                next.append(AB[i][1])
        if AB[i][1] in saitan:
            if list[AB[i][0]] == 0:
                list[AB[i][0]] = AB[i][1]
                next.append(AB[i][0])
    saitan.extend(next)


print("YES")
for ele in list[2:]:
    print(ele)
