#include <iostream>
using namespace std;
#include <bits/stdc++.h>
void DFS(int node,vector<int>b[],vector<int>&parent,vector<int>&used)
{
cout<<node<<" ";
used[node]=1;
for(auto x:b[node])
{
if(used[x]==0)
{
parent[x]=node;
DFS(x,b,parent,used);
}
}
}
int main() {
// your code goes here
int n,m;
cin>>n>>m;
int i;
vector<int>b[n+5];
for(i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
b[x].push_back(y);
b[y].push_back(x);
}
vector<int>used(n+5,0);
vector<int>parent(n+5,0);
DFS(1,b,parent,used);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KCnZvaWQgREZTKGludCBub2RlLHZlY3RvcjxpbnQ+YltdLHZlY3RvcjxpbnQ+JnBhcmVudCx2ZWN0b3I8aW50PiZ1c2VkKQogewogCWNvdXQ8PG5vZGU8PCIgIjsKIAl1c2VkW25vZGVdPTE7CiAJZm9yKGF1dG8geDpiW25vZGVdKQogCSB7CiAJIAlpZih1c2VkW3hdPT0wKSAKIAkgCSB7CiAJIAkgCXBhcmVudFt4XT1ub2RlOwogCSAJIAlERlMoeCxiLHBhcmVudCx1c2VkKTsKIAkgCSB9CiAJIH0KIH0KCmludCBtYWluKCkgewoJLy8geW91ciBjb2RlIGdvZXMgaGVyZQoJaW50IG4sbTsKCWNpbj4+bj4+bTsKCWludCBpOwoJdmVjdG9yPGludD5iW24rNV07Cglmb3IoaT0xO2k8PW07aSsrKQoJIHsKCSAJaW50IHgseTsKCSAJY2luPj54Pj55OwoJIAliW3hdLnB1c2hfYmFjayh5KTsKCSAJYlt5XS5wdXNoX2JhY2soeCk7CgkgfQoJIAoJIHZlY3RvcjxpbnQ+dXNlZChuKzUsMCk7CgkgdmVjdG9yPGludD5wYXJlbnQobis1LDApOwoJIAoJIERGUygxLGIscGFyZW50LHVzZWQpOwoJcmV0dXJuIDA7Cn0=