#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
 /*struct cmp{ bool operator() ( const, const )const{}};
  use as set<ll> ,cmp> a*/
int main()
{
  ios::sync_with_stdio(false);cin.tie(0);
  //freopen("input.txt" , "r" , stdin );
  ll n,m;
  cin>>n>>m;
  vector<ll> a[n+1];
  ll visited[n+1] = {};
  visited[1] = 1;
  for(ll i = 1 ;i<m+1 ;i++)
  {
      ll x,y;
      cin>>x>>y;
      a[x].push_back(y);
      a[y].push_back(x);
  }
  queue<ll> q;
  q.push(1ll);
  vector<ll> distance(n+1,0),position(n+1);
  distance[1] = 0 ;
  
  while(!q.empty())
   {
      ll s = q.front();
      q.pop();
      for( auto it : a[s])
      {
          if(visited[it]) continue;
          visited[it] = 1;
          position[it] = s;
          q.push(it);
      }

  }
  
  bool ok = true;
  if(ok)
  {
      cout<<"YES\n";
      for(ll i = 2 ; i<n+1 ;i++)
        cout<<position[i]<<endl;
  }
  else
  {
      cout<<"NO";
  }

  return 0;
}
