#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef vector VI; typedef vector VVI; typedef vector VS; typedef pair PII; typedef long long LL; typedef vector VLL; typedef unsigned long long ULL; typedef pair PIL; typedef vector VPIL; //#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++) //#define sort(c) sort((c).begin(),(c).end()) #define range(i,a,b) for(int i=(a); i < (b); i++) #define rep(i,n) range(i,0,n) int parent[100001]; int Pre[100002]; int ans[100001]; int root(int x){ if (x != parent[x]) x = root(parent[x]); return parent[x]; } int solve(int n, int x){ if (x <= n) return x; if (ans[x] == -1 && ans[x-n] != -1) ans[x] = ans[x-n] + 1; Pre[x] = solve(n,Pre[x]); return ans[x] == -1 ? x : Pre[x]; } int main(){ int N,M,C,u,v,n,tmp_max; map conn_comp; map :: iterator it; VI comp_num; cin >> N >> M; rep(i,N+2) Pre[i]=i-1; rep(i,N){ans[i+1] = -1; parent[i] = i;} rep(i,M){ cin >> u >> v; u = root(u-1); v = root(v-1); if (u!=v) parent[u] = v; } rep(i,N)conn_comp[root(i)] += 1; for (it=conn_comp.begin();it!=conn_comp.end();it++) comp_num.push_back(it->second); sort(comp_num.begin(),comp_num.end(),greater()); C = comp_num.size(); tmp_max = 0; rep(i,C){ n = comp_num[i]; tmp_max += n; solve(n,tmp_max+1); ans[n] = 0; } rep(i,N) cout << ans[i+1] << endl; return 0; }