#include #include #include #include #include #include #include #include #include #include #include static const int MOD = 1000000007; using ll = long long; using u32 = uint32_t; using namespace std; template constexpr T INF = ::numeric_limits::max()/32*15+208; class UnionFind { int n; public: vector uni; explicit UnionFind(int n) : uni(static_cast(n), -1) , n(n){}; int root(int a){ if (uni[a] < 0) return a; else return (uni[a] = root(uni[a])); } bool unite(int a, int b) { a = root(a); b = root(b); if(a == b) return false; if(uni[a] > uni[b]) swap(a, b); else if(uni[a] == uni[b] && a > b) swap(a, b); uni[a] += uni[b]; uni[b] = a; return true; } int size(int i){ return -uni[root(i)]; } bool same(int a, int b) { return root(a) == root(b); } }; int main() { int n, m; cin >> n >> m; UnionFind uf(n); for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; uf.unite(a-1, b-1); } for (int i = 0; i < n; ++i) { cout << uf.root(i)+1 << "\n"; } return 0; }