#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define all(c) (c).begin(), (c).end() #define zero(a) memset(a, 0, sizeof a) #define minus(a) memset(a, -1, sizeof a) #define minimize(a, x) a = std::min(a, x) #define maximize(a, x) a = std::max(a, x) typedef long long ll; int const inf = 1<<29; struct UnionFind { vector rank; vector rid; UnionFind(int n) { rank.resize(n); rid.assign(n, -1); } void unite(int u, int v) { u = root(u), v = root(v); if(u == v) { return ; } if(rank[u] < rank[v]) { rid[u] = v; } else { rid[v] = u; if(rank[u] == rank[v]) { rank[u]++; } } } bool same(int u, int v) { return root(u) == root(v); } int root(int x) { if(rid[x] < 0) return x; else return rid[x] = root(rid[x]); } }; int main() { int N, M; cin >> N >> M; UnionFind uf(N); rep(i, M) { int u, v; cin >> u >> v; u--, v--; uf.unite(u, v); } map mp; rep(i, N) { mp[uf.root(i)] ++; } /* cout << "----------------\n"; for(auto& e: mp) { cout << e.first << " " << e.second << endl; } cout << endl; cout << "----------------\n"; */ vector nums; for(auto& e: mp) { nums.push_back(e.second); } vector> dp(1);//(100001, {inf, false}); dp[0] = {-1, true}; for(auto& e: nums) { for(int i=dp.size()-1; i>=0; i--) { if(dp[i].second) { if(dp.size() <= i + e) { dp.resize(i + e + 1); } if(!dp[i + e].second || dp[i].first + 1 < dp[i + e].first) { dp[i + e] = {dp[i].first + 1, true}; } if(dp.size() > 100001) { goto exi; } } } } exi:; // rep(i, 10) { cout << i << " " << dp[i].first << " " << dp[i].second << endl; } REP(i, 1, N+1) { if(dp[i].second) { cout << dp[i].first << endl; } else { cout << -1 << endl; } } return 0; }