#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  int *a = new int[m];
  int *b = new int[m];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  int(*e)[3] = new int[m][3];
  for (int i = 0; i < m; i++) {
    e[i][0] = a[i];
    e[i][1] = b[i];
    e[i][2] = 0;
  }
  int(*v)[3] = new int[n][3];
  for (int i = 0; i < n; i++) {
    v[i][0] = 0;
  }
  v[0][0] = 2;
  int count = 1;
  int newcount = 1;
  while (count < n) {
    newcount = count;
    for (int i = 0; i < n; i++) {
      if (v[i][0] != 2) continue;
      for (int j = 0; j < m; j++) {
        if (e[j][2] == 1) continue;
        if (e[j][0] == i && v[e[j][1]][0] == 0) {
          v[e[j][1]][0] = 1;
          v[e[j][1]][1] = i;
        } else if (e[j][1] == i && v[e[j][0]][0] == 0) {
          v[e[j][0]][0] = 1;
          v[e[j][0]][1] = i;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (v[i][0] == 2)
        v[i][0] = 3;
      else if (v[i][0] == 1) {
        v[i][0] = 2;
        newcount++;
      }
    }
    if (count == newcount) {
      cout << "No\n";
      return 0;
    }
    count = newcount;
  }
  for (int i = 1; i < n; i++) {
    cout << v[i][1] + 1 << "\n";
  }
  return 0;
}
