#define _CRT_SECURE_NO_WARNINGS #define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING #include using namespace std; const int N = 2e5 + 50; int adj[N], nxt[N], to[N], ecnt; inline void addEdge(int f, int t) { ecnt++; nxt[ecnt] = adj[f]; adj[f] = ecnt; to[ecnt] = t; } int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0, x, y; i < m; i++) scanf("%d%d", &x, &y), addEdge(x, y), addEdge(y, x); set vis, tov; tov.insert(1); while (vis.size() != n) { int cur = *tov.begin(); tov.erase(tov.begin()); vis.insert(cur); printf("%d ", cur); for (int e = adj[cur]; e; e = nxt[e]) if (vis.count(to[e]) == 0) tov.insert(to[e]); } return 0; }