#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) #if defined(_MSC_VER) || __cplusplus > 199711L #define aut(r,v) auto r = (v) #else #define aut(r,v) __typeof(v) r = (v) #endif #define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it) #define all(o) (o).begin(), (o).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset(m,v,sizeof(m)) #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL using namespace std; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template inline void amin(T &x, U y) { if(y < x) x = y; } template inline void amax(T &x, U y) { if(x < y) x = y; } struct UnionFind { vector data; void init(int n) { data.assign(n, -1); } bool unionSet(int x, int y) { x = root(x); y = root(y); if(x != y) { if(data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool findSet(int x, int y) { return root(x) == root(y); } int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); } int size(int x) { return -data[root(x)]; } }; int main() { int N; int M; while(~scanf("%d%d", &N, &M)) { UnionFind uf; uf.init(N); rep(i, M) { int u; int v; scanf("%d%d", &u, &v), -- u, -- v; uf.unionSet(u, v); } vector counts(N + 1); rep(i, N) if(uf.root(i) == i) ++ counts[uf.size(i)]; vi dp(N + 1, INF); dp[0] = 0; int sum = 0; rer(i, 1, N) { int n = counts[i]; for(int j = 0; (1 << j) <= n; ++ j) if(n >> j & 1) { int s = i << j, t = 1 << j; for(int k = sum; k >= 0; -- k) amin(dp[k + s], dp[k] + t); sum += s; } } rer(i, 1, N) printf("%d\n", dp[i] == INF ? -1 : dp[i] - 1); } return 0; }