let () =
    let main () =
        let n, m = Scanf.sscanf (read_line ()) "%d %d" (fun a b -> a, b) in
        let rec loop i mmin mmax =
            if i = 0 then max 0 (mmax - mmin + 1) else
                let l, r = Scanf.sscanf (read_line ()) "%d %d" (fun l r -> l, r) in
                loop (i - 1) (max mmin l) (min mmax r)
        in
        Printf.printf "%d\n" (loop m 1 n)
    in
    main ()