object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, M = sc.nextInt()
  val (ls, rs) = ((1 -> N) :: List.fill(M)(sc.nextInt() -> sc.nextInt())).unzip
  println((rs.min - ls.max + 1).max(0))
}
