#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; const int INF = (1 << 30) - 1; const ll INF64 = ((ll)1 << 62) - 1; const double PI = 3.1415926535897932384626433832795; const int dx[] = { 0, 1, 0, -1 }; const int dy[] = { -1, 0, 1, 0 }; struct UnionFind { vector data; UnionFind(int n) : data(n, -1) {} int find(int x) { return data[x] < 0 ? x : data[x] = find(data[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) { return false; } if (data[x] > data[y] || data[x] == data[y] && x > y) { swap(x, y); } data[x] += data[y]; data[y] = x; return true; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; UnionFind uf(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; uf.unite(a, b); } for (int i = 0; i < n; i++) { cout << uf.find(i) + 1 << endl; } return 0; }