#include using namespace std; int parent[10001]; int data[10001]; int Find(int x){ if(parent[x] == x) return x; else{ return parent[x] = Find(parent[x]); } } void Union(int x,int y){ int xroot = Find(x); int yroot = Find(y); if(data[xroot] < data[yroot] ||( (data[xroot] == data[yroot]) && xroot > yroot )){ parent[xroot] = yroot; data[yroot] += data[xroot]; } else{ parent[yroot] = xroot; data[xroot] += data[yroot]; } } bool isUnion(int x,int y){ return Find(x) == Find(y); } int main(){ int N,M,A,B; cin >> N >> M; for(int i=1;i<=N;i++){ parent[i] = i; data[i] = 1; } for(int i=0;i> A >> B; if(isUnion(A,B)) continue; Union(A,B); } for(int i=1;i<=N;i++) cout << Find(i) << endl; return 0; }