#include using namespace std; using i64 = long long; #define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++) struct UF{ vector node; UF(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(size(x) > size(y)){ } else if(x > y){ swap(x,y); } node[x] += node[y]; node[y] = x; } }; int main(){ int N,M; cin >> N >> M; UF uf(N + 1); rep(i,0,M - 1){ int a,b; cin >> a >> b; uf.unite(a,b); } rep(i,1,N){ cout << uf.root(i) << endl; } }