#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; class UnionFind { public: vector Parent; UnionFind(ll N) { Parent = vector(N, -1); } ll root(ll A) { if (Parent[A] < 0) { return A; } return Parent[A] = root(Parent[A]); } ll size(ll A) { return -Parent[root(A)]; } bool connect(ll A, ll B) { A = root(A); B = root(B); if (A == B) { return false; } if (size(A) < size(B)) { swap(A, B); } Parent[A] += Parent[B]; Parent[B] = A; return true; } }; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll n, m; scanf("%lld %lld", &n, &m); UnionFind uni(n + 1); map mp; for (ll i = 1; i <= n; i++) mp[i] = i; for (ll i = 0; i < m; i++) { ll a, b; scanf("%lld %lld", &a, &b); if (uni.root(a) == uni.root(b)) continue; if (uni.size(a) < uni.size(b)) swap(a, b); mp.erase(mp.find(uni.root(b))); ll boss = mp[uni.root(a)]; mp.erase(mp.find(uni.root(a))); uni.connect(a, b); mp[uni.root(a)] = boss; } for (ll i = 1; i <= n; i++) { printf("%lld\n", mp[uni.root(i)]); } return 0; }