#include <algorithm>
#include <iostream>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <map>

using namespace std;

#define ll long long
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define pb(x) push_back(x)

ll power(int x, unsigned int y){
    ll res = 1;
    while(y > 0){
        if(y & 1) res = res * x;
        y >>= 1;
        x *= x;
    }
    return res;
}

void dfs(int v, vi arr[], int vis[]){
    vis[v] = 1;

    for(int child : arr[v]){
        if(!vis[child])
            dfs(child, arr,vis);
    }
}

void bfs(int src, vi arr[], int vis[], int dis[]){

    queue<int> q;
    q.push(src);
    dis[src] = 0;
    vis[src] = 1;

    while(!q.empty()){
        int curr = q.front();
        q.pop();

        for(int child : arr[curr]){
            if(!vis[child]){
                vis[child] = 1;
                dis[child] = dis[curr] + 1;
                q.push(child);
            }
        }

    }

}

void solve(){
    int nodes, edges;
    cin >> nodes >> edges;

    vi arr[nodes+1];
    int vis[nodes+1] = {0};

    while(edges--){
        int a, b;
        cin >> a >> b;
        arr[a].pb(b);
        arr[b].pb(a);
    }

    ll connected = 0;

    for(int i = 1; i <= nodes; i++){
        if(!vis[i]){
            dfs(i, arr, vis);
            connected++;
        }
    }

    if(connected > 1) {
        cout << "NO\n";
        return;
    }

    int dis[nodes+1] = {0};

    for(int i = 0; i <= nodes; i++) vis[i] = 0;

    bfs(1, arr, vis, dis);

    cout << "YES\n";
    for(int i = 2; i <= nodes; i++) cout << dis[i] << '\n';
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solve();

}