#include <iostream>
#include <vector>
#include <stack>
using namespace std;
void dfs(vector<vector<int>>& graph, vector<bool>& visited, int start) {
stack<int> s;
s.push(start);
visited[start] = true;
while (!s.empty()) {
int curr = s.top();
cout << curr << " ";
s.pop();
for (int neighbor : graph[curr]) {
if (!visited[neighbor]) {
s.push(neighbor);
visited[neighbor] = true;
}
}
}
}
int main() {
int m, n;
cin >> m >> n;
vector<vector<int>> graph(m);
vector<bool> visited(m, false);
for (int i = 0; i < n; i++) {
int u, v;
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
}
dfs(graph, visited, 0);
cout << endl;
return 0;
}