import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)
  val pass = Array.fill(n+1)(true)

  var l = 1
  var r = n
  Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .foreach { e =>
      l = l max e(0)
      r = r min e(1)
    }
  val ans =( r - l + 1) max 0
  println(ans)
}