#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0; i=b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector VI; typedef vector VL; typedef vector VVI; typedef vector VVL; typedef pair P; typedef pair PL; struct union_find{ VI par, sz; void init(int n){ par.resize(n); sz.resize(n); REP(i,n){ par[i] = i; sz[i] = 1; } } int find(int x){ if (par[x] == x) return x; else return par[x] = find(par[x]); } bool same(int x, int y){ return find(x) == find(y); } void merge(int x, int y){ x = find(x); y = find(y); if (x == y) return; if (sz[x] > sz[y] || (sz[x] == sz[y] && x < y)){ par[y] = x; sz[x] += sz[y]; }else{ par[x] = y; sz[y] += x; } } }; int main(){ int n, m; cin >> n >> m; union_find uf; uf.init(n); while (m--){ int a, b; cin >> a >> b; a--; b--; uf.merge(a, b); } REP(i,n){ printf("%d\n", uf.find(i) + 1); } return 0; }