#include using namespace std; struct Dsu { vector fa, size; Dsu(int n) { fa.assign(n, 0); size.assign(n, 0); for (int i = 0; i < n; ++i) { fa[i] = i; size[i] = 1; } } int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void unite(int x, int y) { int a = find(x); int b = find(y); if (a < b) size[a] += size[b], fa[b] = a; else size[b] += size[a], fa[a] = b; } }; int main() { ios::sync_with_stdio(false); int n, m; cin >> n >> m; Dsu *uf = new Dsu(n); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; --u, --v; uf->unite(u, v); } for (int i = 0; i < n; ++i) { cout << 1 + uf->find(i) << endl; } return 0; }