#include using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() templateostream& operator<<(ostream& os,const pair&a){return os<<"("<void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<bool chmin(T&a,const T&b){return a>b?(a=b,1):0;} templatebool chmax(T&a,const T&b){return a data; UnionFind(int size) : data(size, -1) { } bool link(int x, int y) { x = root(x); y = root(y); if (x != y) { int sx = size(x); int sy = size(y); if (sx > sy || (sx == sy && x < y)) { data[x] += data[y]; data[y] = x; } else { data[y] += data[x]; data[x] = y; } } return x != y; } int root(int x) { // 代表元を返す return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { // 要素xが含まれる集合の大きさ return -data[root(x)]; } }; int nextInt() { int x; scanf("%d", &x); return x;} int main2() { int N = nextInt(); int M = nextInt(); UnionFind uf(N); REP(_, M) { int A = nextInt() - 1; int B = nextInt() - 1; uf.link(A, B); } REP(i, N) { cout << uf.root(i) + 1 << endl; } return 0; } int main() { for (;!cin.eof();cin>>ws) main2(); return 0; }