#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define int long long #define MOD7 1000000007 #define MOD9 1000000009 #define rep(i, n) for (int i = 0; i < (n); i++) #define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++) #define REP(i, a, n) for (int i = (a); i <= (n); i++) #define all(a) (a).begin(), (a).end() using namespace std; int dx[4] = { 1, 0, -1, 0 }; int dy[4] = { 0, -1, 0, 1 }; template void inputVector(vector& v, int n) { v.resize(n); for (int i = 0; i < v.size(); i++) cin >> v[i]; } class UnionFind { private: vector pastNode; class Node { public: int parent; int count; Node(int parent) { this->parent = parent; this->count = 1; } }; vector node; public: UnionFind(int size) { for (int i = 0; i < size; i++) { node.push_back(Node(i)); } } int root(int x) { pastNode.clear(); while (x != node[x].parent) { pastNode.push_back(x); x = node[x].parent; } rep(i, pastNode.size()) { node[pastNode[i]].parent = x; } return x; } void unite(int x, int y) { if (root(x) == root(y)) return; node[root(y)].count += node[root(x)].count; node[root(x)].parent = root(y); } bool same(int x, int y) { return root(x) == root(y); } int countSames(int x) { return node[root(x)].count; } }; signed main() { int N, M; cin >> N >> M; UnionFind uf = UnionFind(N); rep(i, M) { int A, B; cin >> A >> B; A--; B--; if (uf.same(A, B)) continue; if (uf.countSames(A) < uf.countSames(B)) uf.unite(A, B); else if (uf.countSames(A) > uf.countSames(B)) uf.unite(B, A); else if (uf.root(A) < uf.root(B)) uf.unite(B, A); else uf.unite(A, B); } rep(i, N) { cout << uf.root(i) + 1 << endl; } return 0; }