import java.util.Arrays; import java.util.List; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class Main { public static void main(String[] args) { Main main = new Main(); main.run(); } void run() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); int[] A = new int[M]; int[] B = new int[M]; for (int i = 0; i < M; i++) { A[i] = sc.nextInt()-1; B[i] = sc.nextInt()-1; } UnionFind uf=new UnionFind(N); int[] groupsize=new int[N]; Arrays.fill(groupsize,1); for (int i = 0; i < M; i++) { if(uf.same(A[i], B[i])) { continue; } int BossA=uf.root(A[i]); int BossB=uf.root(B[i]); if(groupsize[BossA]groupsize[BossB]) { uf.par[uf.root(BossB)]=uf.root(BossA); groupsize[BossA]+=groupsize[BossB]; }else { //番号が若いほど強いボス。 if(BossA set = new TreeSet(); for (int i = 0; i < par.length; i++) { set.add(this.root(i)); } return set.size(); } public void changeComennt(String yes, String no) { commentYes = yes; commentNO = no; } } //以下テンプレート public static int[] extgcd(int a, int b) { int x0 = 1; int x1 = 0; int y0 = 0; int y1 = 1; while (b != 0) { int q = a / b; int r = a % b; int x2 = x0 - q * x1; int y2 = y0 - q * y1; a = b; b = r; x0 = x1; x1 = x2; y0 = y1; y1 = y2; } return new int[] { a, x0, y0 }; } static int gcd(int a, int b) { if (b == 0) return a; if (a < b) { int t = a; a = b; b = t; } return gcd(b, a % b); } static int lcm(int a, int b) { return a * b / gcd(a, b); } static void swap(int[] a) { int t; t = a[0]; a[0] = a[1]; a[1] = t; return; } static void output(List list) { for (int i = 0; i < list.size(); i++) { System.out.print(list.get(i)); if (i != list.size() - 1) { System.out.print(" "); } else { nl(); } } } static void output(String[][] str) { for (int i = 0; i < str.length; i++) { for (int j = 0; j < str[i].length; j++) { print(str[i][j]); } nl(); } } static void output(boolean flg, String Yes, String No) { if (flg) { pln(Yes); } else { pln(No); } } static void output(String[][] str, int digit) { String dig = "%" + String.valueOf(digit) + "s"; for (int i = 0; i < str.length; i++) { for (int j = 0; j < str[i].length; j++) { System.out.printf(dig, str[i][j]); } nl(); } } static void pln(String str) { System.out.println(str); } static void pln(int x) { System.out.println(x); } static void print(String str) { System.out.print(str); } static void print(int x) { System.out.print(x); } static void print(String str, int times) { for (int i = 0; i < times; i++) { print(str); } } static void print(int x, int times) { for (int i = 0; i < times; i++) { print(x); } } static void nl() { System.out.println(); } }