Scanf.scanf "%d %d" @@ fun n m ->
  let lrs = Array.init m @@ fun _ -> Scanf.scanf " %d %d" @@ fun l r -> l, r in
  let f (l, r) (l1, r1) = max l l1, min r r1 in
  let l, r = Array.fold_left f lrs.(0) lrs in
  Printf.printf "%d\n" @@ max 0 @@ r - l + 1