#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m, u, v, vis[N];
vector<int> seq, g[N];
priority_queue<int, vector<int>, greater<int>> Q;
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vis[1] = 1;
  Q.push(1);
  while (!Q.empty()) {
    int v = Q.top();
    seq.push_back(v);
    Q.pop();
    for (auto i : g[v])
      if (!vis[i]) {
        vis[i] = 1;
        Q.push(i);
      }
  }
  for (auto o : seq) cout << o << " ";
}
