#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long INF = 1e18;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ' ';
    cout << v[i];
  }
  cout << '\n';
  return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
  for (int i = 0; i < v.size(); i++) cout << v[i];
  cout << '\n';
  return os;
}
void precalc() {}
vector<vector<int>> G;
vector<int> used;
void solve() {
  int n, m;
  cin >> n >> m;
  G = vector<vector<int>>(n + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  used = vector<int>(n + 1, 0);
  priority_queue<int> pq;
  pq.push(-1);
  while (!pq.empty()) {
    int cur = -pq.top();
    pq.pop();
    cout << cur << ' ';
    used[cur] = 1;
    for (auto v : G[cur])
      if (!used[v]) {
        used[v] = 1;
        pq.push(-v);
      }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  precalc();
  solve();
  return 0;
}
