(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let n, m = Scanf.sscanf (read_line ()) "%d %d" ( fun n m -> n, m)

let slst = List.init m (
        fun _ -> 
                Scanf.sscanf (read_line ()) "%d %d" (
                        fun l r -> 
                                (l, r)
                )
) |> List.map (fun (l, r) -> Set.of_list (List.range l `To r))

let rec f lst =
        match lst with
                  [] -> Set.of_list []
                | first :: [] -> 
                        first
                | first :: rest -> 
                        Set.intersect first (f rest)

let () =
        f slst
        |> Set.cardinal
        |> Printf.printf "%d\n"

