#include <bits/stdc++.h>
using namespace std;

void dfs(int node, vector<int> Graph[], vector<int>& vis, vector<int>& parent) {
	cout << node << endl;
	
	vis[node] = 1;
	
	for(auto u : Graph[node]) { // iterating all children "u" of "node"
		if(vis[u] == 0) {
			// if this node/branch has never been visited before
			// just go into it and search it using dfs in recursion
			parent[u] = node;
			dfs(u, Graph, vis, parent);
		}
	}
}

int main() {
	int n;
	cin >> n;
 
	int m;
	cin >> m;
 
	vector<int> Graph[n+5];
 
	for(int i=0; i<m; i++) {
		int x, y;
 
		cin >> x >> y;
 
		Graph[x].push_back(y);
		Graph[y].push_back(x);
	}
 
	vector<int> vis(n+5, 0);
	vector<int> parent(n+5, 0);
	
	dfs(1, Graph, vis, parent); // starts from source node
	return 0;
}