#include using namespace std; using i64 = long long; #define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++) #include using namespace std; struct UnionFind { vector par; vector cnt; void init(int size) { par.resize(size, 0); cnt.resize(size,1); for (int i = 0; i < size; i++) { par[i] = i; } } int root(int x) { return par[x] == x ? x : par[x] = root(par[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if(cnt[x] < cnt[y]){ par[x] = y; root(x); root(y); cnt[y] += cnt[x]; cnt[x] = 0; } else if(cnt[x] > cnt[y]){ par[y] = x; root(x); root(y); cnt[x] += cnt[y]; cnt[y] = 0; } else if(x > y){ par[x] = y; root(x); root(y); cnt[y] += cnt[x]; cnt[x] = 0; } else{ par[y] = x; root(x); root(y); cnt[x] += cnt[y]; cnt[y] = 0; } return true; } }; int main(){ int N; int M; cin >> N >> M; UnionFind uf; uf.init(N + 1); rep(i,0,M - 1){ int a,b; cin >> a >> b; uf.unite(a,b); } rep(i,1,N){ cout << uf.root(i) << endl; } }