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.Collections; 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; import java.util.TreeMap; public class Main_yukicoder317 { 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]; List cnt = new ArrayList(); 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++; } } cnt.add(tmp); } Map hm = new TreeMap(Collections.reverseOrder()); hm.put(0, 0); for (int e : cnt) { Map tmp = new HashMap(hm); for (Entry es : tmp.entrySet()) { if (hm.containsKey(es.getKey() + e)) { if (hm.get(es.getKey() + e) > es.getValue() + 1) { hm.put(es.getKey() + e, es.getValue() + 1); } } else { hm.put(es.getKey() + e, es.getValue() + 1); } } } for (int i = 0; i < n; i++) { if (hm.containsKey(i + 1)) { pr.println(hm.get(i + 1) - 1); } else { pr.println(-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); } } }