// Template {{{ #include #define REP(i,n) for(int i=0; i<(int)(n); ++i) using namespace std; typedef long long LL; #ifdef LOCAL #include "contest.h" #else #define dump(x) #endif const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; inline bool valid(int x, int w) { return 0 <= x && x < w; } void iostream_init() { ios::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(12); } //}}} struct UnionFind { vector data; UnionFind(int N) : data(N, -1) { } // xとyを併合する bool unite(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } // xとyが同じ集合にあるか判定する bool same(int x, int y) { return root(x) == root(y); } // xを含む集合の要素数を求める int size(int x) { return -data[root(x)]; } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } }; int main(){ iostream_init(); int N, M; while(cin >> N >> M) { UnionFind uf(N); REP(i, M) { int a, b; cin >> a >> b; a--; b--; uf.unite(a, b); } map counter; REP(i, N) if(uf.root(i) == i) { int size = uf.size(i); counter[size] ++; } const int INF = 1e9; vector min_cost(N + 1, INF); min_cost[0] = 0; for(const auto& p : counter) { int size = p.first; int count = p.second; for(int k = 0; count > 0; k++) { int use = min(count, 1 << k); int value = size * use; int cost = 1 * use; for(int i = N - value; i >= 0; i--) { min_cost[i + value] = min(min_cost[i + value], min_cost[i] + cost); } count -= use; } } REP(i, N) { int ans = min_cost[i+1]; cout << (ans == INF ? -1 : ans-1) << endl; } } return 0; }