open System

let rec passAll preds (target: 'A) =
    match preds with
    | [] -> true
    | f::fs ->
        if f target then
            passAll fs target 
        else
            false

module Gate =
    type T = int list
    
    let init (l: int) (r: int): T = [l..r]
    
    let pass (gate: T) (cardId: int): bool = List.contains cardId gate
    
[<EntryPoint>]
let main _ =
    let input = Console.ReadLine()
    let [| n; m |] = input.Split(' ') |> Array.map Int32.Parse
    let getGate _ =
        let line = Console.ReadLine()
        let [|l; r|] = line.Split(' ') |> Array.map Int32.Parse
        Gate.init l r
    let cards = [1..n]
    let gatePreds = List.map (getGate >> Gate.pass) [1..m]
    List.filter (passAll gatePreds) cards
    |> List.length
    |> printfn "%d"
    
    0
