#include using namespace std; using ll = long long; using PII = std::pair; using PLL = std::pair; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) class Unionfind { vector p; vector q; public: int find(int x); void unite(int x, int y); Unionfind(int n); }; Unionfind::Unionfind(int n) { for (int i = 0; i < n; i++) { p.push_back(i); q.push_back(1); } } int Unionfind::find(int x) { while (p[x] != x) { p[x] = p[p[x]]; x = p[x]; } return x; } void Unionfind::unite(int x, int y) { x = Unionfind::find(x); y = Unionfind::find(y); if (x > y) swap(x, y); if (x != y) { if (q[x] >= q[y]) { p[y] = x; q[x] += q[y]; q[y] = 0; } else { p[x] = y; q[y] += q[x]; q[x] = 0; } } } int main() { #ifdef DEBUG cout << "DEBUG MODE" << endl; ifstream in("input.txt"); //for debug cin.rdbuf(in.rdbuf()); //for debug #endif int n, m, x, y; cin >> n >> m; Unionfind monkeys(n); rep(i, m) { cin >> x >> y; x--, y--; monkeys.unite(x, y); } rep(i, n) cout << monkeys.find(i) + 1 << endl; return 0; }