#include #define ll long long #define inf 2147483647 //9223372036854775807 using namespace std; inline int rd() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar(); return x * f; } int fa[100005], siz[100005], cnt[100005], v[100005], w[100005], f[100005]; int fd(int x) { return fa[x] == x ? x : fa[x] = fd(fa[x]); } signed main() { // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); int n = rd(), m = rd(); for(int i = 1; i <= n; i++) fa[i] = i, siz[i] = 1; for(int i = 1; i <= m; i++) { int x = fd(rd()), y = fd(rd()); if(x == y) continue; fa[y] = x, siz[x] += siz[y]; } for(int i = 1; i <= n; i++) if(fd(i) == i) cnt[siz[i]]++; int tot = 0; for(int i = 1; i <= n; i++) if(cnt[i]) for(int j = 1; cnt[i]; j <<= 1) if(cnt[i] >= j) cnt[i] -= j, w[++tot] = i * j, v[tot] = j; else w[++tot] = i * cnt[i], v[tot] = cnt[i], cnt[i] = 0; for(int i = 1; i <= n; i++) f[i] = 1e9; for(int i = 1; i <= tot; i++) for(int j = n; j >= w[i]; j--) f[j] = min(f[j], f[j - w[i]] + v[i]); for(int i = 1; i <= n; i++) if(f[i] < 1e9) cout << f[i] - 1 << '\n'; else cout << -1 << '\n'; return 0; } /* ylcccx */