#include using namespace std; struct Dsu { vector fa, size; Dsu(int n) { fa.assign(n, 0); size.assign(n, 1); for (int i = 0; i < n; ++i) { fa[i] = i; } } int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void unite(int x, int y) { size[find(x)] += size[find(y)]; fa[find(y)] = find(x); } }; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; Dsu *uf = new Dsu(n); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; --u, --v; int su = uf->size[uf->find(u)]; int sv = uf->size[uf->find(v)]; if (su > sv or (su == sv and uf->find(u) < uf->find(v))) { uf->unite(u, v); } else { uf->unite(v, u); } } for (int i = 0; i < n; ++i) { cout << 1 + uf->find(i) << endl; } return 0; }