#include <bits/stdc++.h>
using namespace std;
vector<int> v[100003];
int visited[100003];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int m, n, a, b;
  cin >> n >> m;
  while (m--) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  priority_queue<int, vector<int>, greater<int>> pq;
  pq.push(1);
  visited[1] = 1;
  while (!pq.empty()) {
    int t = pq.top();
    cout << t << " ";
    pq.pop();
    for (int i : v[t]) {
      if (!visited[i]) {
        visited[i] = 1;
        pq.push(i);
      }
    }
  }
  cout << "\n";
  return 0;
}
