'use strict';

function Main(input) {
  const N = Number(input.split('\n')[0].split(' ')[0]);
  const M = Number(input.split('\n')[0].split(' ')[1]);
  let list = input.split('\n').slice(1).map(x => x.split(' '));
  list.sort((x, y) => Math.abs(Number(x[0]) - Number(x[1])) - Math.abs(Number(y[0]) - Number(y[1])));

  const bridgecenter = N / 2;

  let breaklist = [];

  //配列比較用
  const diff = (array1, array2) => array2.filter((a, b) => array1[b] !== a);

  for(let i=0; i<M; i++) {
    //壊す場所の選択肢
    let select = [];
    for (let j = Number(list[i][0]); j<list[i][1]; j++) {
      select.push(j);
    }
    // console.log(select);
    // console.log(diff(breaklist, select));
    // console.log(diff(breaklist, select).length === select.length);
    //if 選択肢のどれかがあれば処理せず、なければ中心に近いところを壊す
    if (diff(breaklist, select).length === select.length) {
      let diffcenter = select.map(x => Math.abs(x - bridgecenter));
      let choiced = diffcenter.indexOf(Math.min.apply(null, diffcenter));
      breaklist.push(select[choiced]);
    }

  }

  breaklist = breaklist.filter((x, i, self) => self.indexOf(x) === i);

  console.log(breaklist.length);

};

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
