import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; public class Main_yukicoder317_3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int n = sc.nextInt(); int m = sc.nextInt(); List> edges = new ArrayList>(); for (int i = 0; i < n; i++) { edges.add(new ArrayList()); } for (int i = 0; i < m; i++) { int u = sc.nextInt() - 1; int v = sc.nextInt() - 1; edges.get(u).add(v); edges.get(v).add(u); } boolean[] used = new boolean[n]; Map cnt = new HashMap(); for (int i = 0; i < n; i++) { if (used[i]) { continue; } Deque st = new ArrayDeque(); st.push(i); used[i] = true; int tmp = 1; while (!st.isEmpty()) { int v = st.pop(); for (int e : edges.get(v)) { if (used[e]) { continue; } st.push(e); used[e] = true; tmp++; } } if (cnt.containsKey(tmp)) { cnt.put(tmp, cnt.get(tmp) + 1); } else { cnt.put(tmp, 1); } } int[] dp = new int[n + 1]; final int INF = Integer.MAX_VALUE / 2; Arrays.fill(dp, INF); dp[0] = 0; Deque qi = new ArrayDeque(); Deque qdp = new ArrayDeque(); for (Entry v : cnt.entrySet()) { int w = v.getKey(); int nn = v.getValue(); for (int j = 0; j < w; j++) { qi.clear(); qdp.clear(); for (int i = 0; i * w + j <= n; i++) { int tmp = dp[i * w + j] - i; while (!qi.isEmpty() && qdp.peekLast() >= tmp) { qi.removeLast(); qdp.removeLast(); } qi.add(i); qdp.addLast(tmp); dp[i * w + j] = qdp.peekFirst() + i; if (qi.peekFirst() == i - nn) { qi.removeFirst(); qdp.removeFirst(); } } } } for (int i = 1; i <= n; i++) { if (dp[i] == INF) { pr.println(-1); } else { pr.println(dp[i] - 1); } } pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { it = Arrays.asList(br.readLine().split(" ")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }