'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n').map(v => v.split(' ').map(n => Number(n)))
  const N = input[0][0]
  const M = input[0][1]
  input.shift()
  let ans = []
  for (let i = 0; i < M; i++) {
    const tmp = ans

    for (let j = 0; j < M; j++) {
      if (j >= i) {
        tmp.push(input[j][0])
      }
      if (j <= i) {
        tmp.push(input[j][1])
      }
    }

    if (i <= 0) {
      ans = tmp
      continue
    }
    ans = tmp.filter(function (x, i, self) {
      return self.indexOf(x) === i && i !== self.lastIndexOf(x)
    })
  }
  if (ans.length >= 2) {
    ans = ans.sort((a, b) => a - b)
    console.log(ans[ans.length - 1] - ans[0] + 1)
  } else {
    console.log(ans.length)
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
