#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() using namespace std; typedef long long ll; typedef pair pi; typedef pair pl; typedef pair plc; int par[100010], rnk[100010]; void init(int n) { for (int i = 1; i <= n; i++) { par[i] = i; rnk[i] = 1; } } int find(int x) { if (par[x] == x)return x; else return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; if (rnk[x] < rnk[y])swap(x, y); if (rnk[x] == rnk[y] && x > y)swap(x, y); par[y] = x; rnk[x] += rnk[y]; rnk[y] = 0; return; } bool same(int x, int y) { return find(x) == find(y); } int main() { int n,m; cin >> n >> m; init(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; unite(a,b); } for (int i = 1; i <= n; i++) { cout << find(i) << endl; } return 0; }