#include using namespace std; #define rep(i,j,n) for(int i=(j);i<(n);i++) #define erep(i,j,n) for(int i=(j);i<=(n);i++) #define all(i) i.begin(),i.end() #define rall(i) i.rbegin(),i.rend() #define INF 1e9 const int mod = 1e9+7; typedef vector vi; typedef vector vs; typedef vector vvi; typedef pair pi; typedef long long i64; struct UnionFind { vector node; UnionFind(int sz) { node.resize(sz, -1); } int root(int x) { return (node[x] < 0 ? x : node[x] = root(node[x])); } int size(int x) { return -node[root(x)]; } void unite(int x, int y) { x = root(x); y = root(y); if(x == y) return; if(size(x) < size(y)) { swap(x, y); } else if(x > y) { swap(x, y); } node[x] += node[y]; node[y] = x; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; UnionFind uf(n + 1); rep(i, 0, m) { int a, b; cin >> a >> b; uf.unite(a, b); } erep(i, 1, n) cout << uf.root(i) << endl; }