#include using namespace std; struct UnionFind { vectorpar; vectorsize; UnionFind(int x) { par.resize(x); size.resize(x, 1); for(int i = 0; i < x; i++) { par[i] = i; } } int find(int x) { if(par[x] == x) { return x; } return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } int consize(int x) { return size[find(x)]; } void unite(int x, int y) { x = find(x); y = find(y); if(x == y) { return; } if(size[x] < size[y]) { par[x] = y; size[y] += size[x]; } else if(size[x] > size[y]){ par[y] = x; size[x] += size[y]; } else if(x < y) { par[y] = x; size[x] += size[y]; } else { par[x] = y; size[y] += size[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; uf.unite(A-1,B-1); } for(int i = 0; i < N; i++) { cout << uf.find(i)+1 << endl; } }