#include #define rep(i, a, n) for(int i = a; i < n; i++) #define repb(i, a, b) for(int i = a; i >= b; i--) #define all(a) a.begin(), a.end() #define o(a) cout << a << endl #define int long long using namespace std; typedef pair P; struct UF{ vector par; vector sz; UF(){} UF(int n){ par.resize(n); sz.resize(n, 1); rep(i, 0, n) par[i] = i; } int find(int x){ if(x == par[x]) return x; return par[x] = find(par[x]); } void unite(int x, int y){ x = find(x); y = find(y); if(x == y) return; if(sz[x] < sz[y]) swap(x, y); if(sz[x] == sz[y] && x > y) swap(x, y); sz[x] += sz[y]; par[y] = x; } bool same(int x, int y){ return find(x) == find(y); } }; signed main(){ int n, m; cin >> n >> m; UF uf(n); rep(i, 0, m){ int a, b; cin >> a >> b; a--; b--; uf.unite(uf.find(a), uf.find(b)); } rep(i, 0, n){ cout << uf.find(i) + 1 << endl; } }