fun main(args: Array<String>) {
  val (N, M) = readLine()!!.split(" ").map{ it.toInt() }
  var (min, max) = readLine()!!.split(" ").map{ it.toInt() }
  var result = 0
  val start_index = 2
  val last_index  = M
  for (i in start_index..last_index) {
    val (L, R) = readLine()!!.split(" ").map{ it.toInt() }
    when {
      max < L -> {
        println(0)
        return
      }
      min <= L && L <= max -> min = L
    }
    when {
      R < min -> {
        println(0)
        return
      }
      min <= R && R <= max -> max = R
    }
  }
  
  result = max - min + 1
  println(result)
  
}
    
