'use strict'


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

