import scala.io.{StdIn => in}

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

  val (l, r) = Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    ./:((1, n)) { case ((l, r), e) =>
      (l max e(0), r min e(1))
    }

  val ans = (1 + r - l) max 0
  println(ans)
}