'use strict'

function Main(input) {
  input = input.split('\n');
  let tmp = input.shift().split(/\s/);
  let N = parseInt(tmp[0]);
  let M = parseInt(tmp[1]);
  let array = input.map(str => str.split(/\s/).map(a => a-0));
  let resultArray=[];
  let count = 0;
  for(let i=0;i<M;i++){
    let leftIndex = -1;
    let rightIndex = -1;
    for(let j=0;j<resultArray.length;j++){
      if(resultArray[j][array[i][0]] != undefined && resultArray[j][array[i][0]] != null){
        leftIndex=j;
      }
      if(resultArray[j][array[i][1]] != undefined && resultArray[j][array[i][1]] != null){
        rightIndex=j;
      }
    }
    if(leftIndex != -1 && rightIndex == -1) {
      resultArray[leftIndex][array[i][1]]=0;
      count++;
    } else if(leftIndex == -1 && rightIndex != -1) {
      resultArray[rightIndex][array[i][0]] = 0;
      count++;
    } else if(leftIndex == -1 && rightIndex == -1) {
      let tmp = {}
      tmp[array[i][0]]=0;
      tmp[array[i][1]]=0;
      resultArray.push(tmp);
      count += 2;
    }
  }
  console.log(resultArray.length + N - count)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
