#include using namespace std; int uf[10001]; int find(int x) { if (uf[x] < 0) { return x; } return uf[x] = find(uf[x]); } void merge(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (abs(uf[x]) == abs(uf[y])) { if (x < y) { uf[x] += uf[y]; uf[y] = x; } else { uf[y] += uf[x]; uf[x] = y; } } else if (abs(uf[x]) < abs(uf[y])) { uf[y] += uf[x]; uf[x] = y; } else { uf[x] += uf[y]; uf[y] = x; } return; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, m, a, b; memset(uf, -1, sizeof(uf)); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a >> b; merge(a, b); } for (int i = 1; i <= n; i++) { cout << find(i) << '\n'; } return 0; }