#include using namespace std; typedef long long ll; #define F first #define S second #define pii pair #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() #define inf (int)(1e9+7) #define abs(x) (x >= 0 ? x : -(x)) #define ceil(a, b) a / b + !!(a % b) template inline void chmin(T1 &a, T2 b) { if (a > b) a = b; } template inline void chmax(T1 &a, T2 b) { if (a < b) a = b; } ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } template T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } struct UnionFind { vector data; int sz; UnionFind(int sz) : data(sz, -1) { sz = sz; } bool connect(int x, int y) { if ((x = root(x)) == (y = root(y))) return false; if (data[x] > data[y]) swap(x, y); else if (data[x] == data[y]) { if (root(x) > root(y)) swap(x, y); } data[x] += data[y]; data[y] = x; sz--; return true; } bool issame(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return sz; } }; int main() { int n, m; cin >> n >> m; UnionFind uni(n); rep(i, m) { int x, y; cin >> x >> y; x--; y--; uni.connect(x, y); } rep(i, n) cout << uni.root(i) + 1 << '\n'; }