#include using namespace std; namespace fastio { static constexpr int SZ = 1 << 17; char ibuf[SZ], obuf[SZ]; int pil = 0, pir = 0, por = 0; struct Pre { char num[40000]; constexpr Pre() : num() { for (int i = 0; i < 10000; i++) { int n = i; for (int j = 3; j >= 0; j--) { num[i * 4 + j] = n % 10 + '0'; n /= 10; } } } } constexpr pre; inline void load() { memcpy(ibuf, ibuf + pil, pir - pil); pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin); pil = 0; } inline void flush() { fwrite(obuf, 1, por, stdout); por = 0; } inline void rd(char& c) { c = ibuf[pil++]; } template inline void rd(T& x) { if (pil + 32 > pir) load(); char c; do c = ibuf[pil++]; while (c < '-'); bool minus = 0; if (c == '-') { minus = 1; c = ibuf[pil++]; } x = 0; while (c >= '0') { x = x * 10 + (c & 15); c = ibuf[pil++]; } if (minus) x = -x; } inline void rd() {} template inline void rd(Head& head, Tail&... tail) { rd(head); rd(tail...); } inline void wt(char c) { obuf[por++] = c; } template inline void wt(T x) { if (por > SZ - 32) flush(); if (!x) { obuf[por++] = '0'; return; } if (x < 0) { obuf[por++] = '-'; x = -x; } int i = 12; char buf[16]; while (x >= 10000) { memcpy(buf + i, pre.num + (x % 10000) * 4, 4); x /= 10000; i -= 4; } int d = x < 100 ? (x < 10 ? 1 : 2) : (x < 1000 ? 3 : 4); memcpy(obuf + por, pre.num + x * 4 + 4 - d, d); por += d; memcpy(obuf + por, buf + i + 4, 12 - i); por += 12 - i; } inline void wt() {} template inline void wt(Head head, Tail... tail) { wt(head); wt(tail...); } template inline void wtn(T x){ wt(x, '\n'); } struct Dummy { Dummy() { atexit(flush); } } dummy; } using fastio::rd; using fastio::wt; using fastio::wtn; struct UnionFind { vector data; UnionFind(int N) : data(N, -1) {} int find(int k) { return data[k] < 0 ? k : data[k] = find(data[k]); } int unite(int x, int y) { if ((x = find(x)) == (y = find(y))) return false; if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return true; } int size(int k) { return -data[find(k)]; } int same(int x, int y) { return find(x) == find(y); } }; void run_atcoder_library_check_A() { int N, Q; rd(N, Q); UnionFind uf(N); while (Q--) { int t, u, v; rd(t, u, v); if (t) wtn(uf.same(u, v)); else uf.unite(u, v); } } int main() { int n, m; rd(n, m); UnionFind uf(n); for (int i = 0; i < m; i++){ int a, b; rd(a, b); a--, b--; int p = uf.find(a); int q = uf.find(b); bool w = uf.size(p) > uf.size(q); if (uf.size(p) == uf.size(q)) { w = p < q; } if (w) uf.unite(p, q); else uf.unite(q, p); } for (int i = 0; i < n; i++) { if (uf.data[i] < 0) wtn(i + 1); else wtn(uf.find(i) + 1); } return 0; }