#include using namespace std; #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) #define unless(p) if(!(p)) #define until(p) while(!(p)) using ll = long long; using P = std::tuple; const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; template struct UnionFind{ UnionFind(){ for(int i=0;i rank[y]){ par[y] = x; cnt[x] += cnt[y]; boss[x] = b; }else{ par[x] = y; cnt[y] += cnt[x]; boss[y] = b; if(rank[x] == rank[y]){rank[y]++;} } } int rank[n], par[n], cnt[n], boss[n]; }; UnionFind<10100> uf; int N, M; int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cin >> N >> M; for(int i=0;i> a >> b; int pa = uf.find(a), pb = uf.find(b); if(uf.cnt[pa] > uf.cnt[pb] || (uf.cnt[pa] == uf.cnt[pb] && uf.boss[pa] < uf.boss[pb])){ uf.unite(pa, pb, uf.boss[pa]); }else{ uf.unite(pa, pb, uf.boss[pb]); } // for(int j=1;j<=N;++j){ // std::cout << uf.boss[uf.find(j)] << " \n"[j == N]; // } } for(int i=1;i<=N;++i){ int b = uf.boss[uf.find(i)]; std::cout << b << std::endl; } }