#include #define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++) using namespace std; typedef long long ll; ll N,M,A,B; class unionFind { vector a; public: unionFind(ll n) { REP(i, 0, n) a.push_back(-1); } ll find(ll i) { return a[i] < 0 ? i : (a[i] = find(a[i])); } bool unite(ll i, ll j) { if (find(i) == find(j)) return false; a[find(i)] += a[find(j)]; a[find(j)] = find(i); return true; } ll size(ll i) { return -a[find(i)]; } }; int main(void) { cin >> N >> M; unionFind uf(N); REP (i, 0, M) { cin >> A >> B, A--, B--; if (uf.size(A) > uf.size(B)) uf.unite(A, B); else if (uf.size(A) < uf.size(B)) uf.unite(B, A); else { if (uf.find(A) < uf.find(B)) uf.unite(A, B); else uf.unite(B, A); } } REP(i, 0, N) cout << uf.find(i) + 1 << endl; return 0; }