#include <bits/stdc++.h>
template <typename T>
struct cmp {
  bool operator()(const T& lhs, const T& rhs) { return lhs > rhs; }
};
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, m;
  std::cin >> n >> m;
  std::vector<std::vector<int>> edge(n + 1);
  int min_node = n + 1;
  for (int i = 0; i < m; ++i) {
    int u, v;
    std::cin >> u >> v;
    edge[u].push_back(v);
    edge[v].push_back(u);
    min_node = std::min({min_node, u, v});
  }
  std::vector<bool> visited(n + 1, false);
  std::vector<int> ans;
  std::priority_queue<int, std::vector<int>, cmp<int>> pq;
  pq.push(min_node);
  visited[min_node] = true;
  while (!pq.empty()) {
    auto u = pq.top();
    pq.pop();
    ans.push_back(u);
    for (auto v : edge[u]) {
      if (!visited[v]) {
        visited[v] = true;
        pq.push(v);
      }
    }
  }
  for (auto x : ans) std::cout << x << ' ';
  std::cout << '\n';
  return 0;
}
