#include #define GET_MACRO(a, b, c, NAME, ...) NAME #define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define rep2(i, a) rep3 (i, 0, a) #define rep3(i, a, b) for (int i = (a); i < (b); i++) #define repr(...) GET_MACRO(__VA_ARGS__, repr3, repr2)(__VA_ARGS__) #define repr2(i, a) repr3 (i, 0, a) #define repr3(i, a, b) for (int i = (b) - 1; i >= (a); i--) template inline bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } using namespace std; typedef long long ll; const int inf = 1e9; struct UF { vector parent, size; UF(int n) : parent(n), size(n, 1) { rep (i, n) parent[i] = i; } int root(int x) { if (x == parent[x]) return x; else return parent[x] = root(parent[x]); } void merge(int x, int y) { x = root(x); y = root(y); if (x == y) return; if (size[x] < size[y]) swap(x, y); size[x] += size[y]; parent[y] = x; } bool same(int x, int y) { return root(x) == root(y); } }; int dp[101010]; int main() { int n, m; cin >> n >> m; UF uf(n); rep (i, m) { int u, v; scanf("%d %d", &u, &v); u--; v--; uf.merge(u, v); } map mp; rep (i, n) if (uf.root(i) == i) mp[uf.size[i]]++; rep (i, 101010) dp[i] = inf; dp[0] = 0; for (auto kv : mp) { int val = kv.first, num = kv.second; for (int k = 1; num > 0; k <<= 1) { int c = min(k, num); repr (j, val * c, n + 1) { chmin(dp[j], dp[j - val * c] + k); } num -= c; } } rep (i, 1, n + 1) { if (dp[i] > n) dp[i] = 0; printf("%d\n", dp[i] - 1); } return 0; }