#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair pii; struct UnionFind { vector data; UnionFind(int size) : data(size, -1){ } bool unionSet(int x, int y) { x = root(x); y = root(y); if (x != y) { if(size(x) > size(y)) { data[x] += data[y]; data[y] = x; } else if(size(x) < size(y)) { data[y] += data[x]; data[x] = y; } else { if(x < y) { data[x] += data[y]; data[y] = x; } else { data[y] += data[x]; data[x] = y; } } } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; int main() { int n, m; cin >> n >> m; UnionFind uf(n); for(int i = 0;i < m;i++) { int a, b; cin >> a >> b; a--; b--; uf.unionSet(a, b); } for(int i = 0;i < n;i++) { cout << uf.root(i) + 1 << endl; } return 0; }