#include <bits/stdc++.h>
using namespace std;
const int Mod = 1000000007;
const int N = 100009;
bool Mark[N];
vector<int> adj[N];
priority_queue<int> PQ;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int n, m, u, v;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  PQ.push(-1);
  while (PQ.size() > 0) {
    int node = -PQ.top();
    PQ.pop();
    if (Mark[node]) continue;
    Mark[node] = true;
    cout << node << " ";
    for (auto ch : adj[node]) {
      PQ.push(-ch);
    }
  }
  cout << "\n";
}
