#include using namespace std; using int64 = long long; using uint64 = unsigned long long; struct uf_tree { std::vector parent; int __size; uf_tree(int size_) : parent(size_, -1), __size(size_) {} void unite(int x, int y) { if ((x = find(x)) != (y = find(y))) { // size[y] > size[x] if (-parent[y] > -parent[x] or (parent[y] == parent[x] and y < x)) std::swap(x, y); parent[x] += parent[y]; parent[y] = x; __size--; } } bool is_same(int x, int y) { return find(x) == find(y); } int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); } int size(int x) { return -parent[find(x)]; } int size() { return __size; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, M; cin >> N >> M; uf_tree uf(N); for (int i = 0; i < M; i++) { int a, b; cin >> a >> b; a--; b--; uf.unite(a, b); } for (int i = 0; i < N; i++) { cout << uf.find(i) + 1 << endl; } return 0; }