#include using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) typedef long long ll; const int MOD = 1e9 + 7; const ll INF = LLONG_MAX / 2; struct union_find { vector v; union_find(int n) : v(n, -1) {} int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (-v[x] < -v[y]) swap(x, y); v[x] += v[y]; v[y] = x; } bool root(int x) { return v[x] < 0; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return -v[find(x)]; } }; int main() { int N, Q; cin >> N >> Q; vector boss(N); rep(i, N) boss[i] = i; union_find uf(N); while (Q--) { int i, j; scanf("%d%d", &i, &j); i--, j--; if (uf.same(i, j)) continue; i = uf.find(i), j = uf.find(j); if (uf.size(i) < uf.size(j)) swap(i, j); else if (uf.size(i) == uf.size(j) && boss[i] > boss[j]) swap(i, j); uf.unite(i, j); int k = uf.find(i); boss[k] = boss[i]; } rep(i, N) cout << boss[uf.find(i)] + 1 << endl; }