#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;
const int N = 1e5 + 10;
int n, m, u, v, mark[N];
vector<int> ans, g[N];
priority_queue<int> pq;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v), g[v].push_back(u);
  }
  pq.push(-1), mark[1] = 1;
  while (!pq.empty()) {
    int cur = pq.top();
    pq.pop(), ans.push_back(-cur);
    for (auto &u : g[-cur])
      if (!mark[u]) mark[u] = 1, pq.push(-u);
  }
  for (auto &u : ans) printf("%d ", u);
}
