#include using namespace std; int n, m, e, h[1145141], ne[1145141], t[1145141], u, v, b[1145141], is[1145141], cnt, f[1145][114514]; int ct (int x, int y) { e++; ne[e] = h[x]; h[x] = e; t[e] = y; return 0; } int dfs(int x, int y) { is[x] = 1; b[y]++; for (int i = h[x]; i; i = ne[i]) { if (!is[t[i]]) { dfs(t[i], y); } } return 0; } int main () { cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> u >> v; ct(u, v); ct(v, u); } for (int i = 1; i <= n; i++) { if(!is[i]) { dfs(i, ++cnt); } } // memset(f, 0x3f, sizeof(f)); for (int i = 0; i <= 1000; i++) { for (int j = 1; j <= n; j++) { f[i][j] = 11451419; } } f[0][0] = 0; for (int i = 1; i <= cnt; i++) { for (int j = n; j >= b[i]; j--) { f[i][j] = min(f[(i - 1)][j - b[i]] + 1, f[(i - 1)][j]); // cout << f[(i - 1)][j - b[i]] + 1 << " " << f[(i - 1)][j] << "\n"; //cout << f[i][j] << " "; } for (int j = b[i] - 1; j; j--) f[i][j] = f[(i - 1)][j]; // cout << "\n"; f[i][b[i]] = 0; } for (int i = 1; i <= n; i++) { if (f[cnt][i] >= 11451419) cout << "-1\n"; else cout << f[cnt][i] << "\n"; } }