open System

let getSet l r = Set.ofList [l..r]
let getGateSet _ =
    let line = Console.ReadLine()
    let [|l; r|] = line.Split(' ') |> Array.map Int32.Parse
    getSet l r

[<EntryPoint>]
let main _ =
    let [|n; m|] =
        let line = Console.ReadLine()
        line.Split(' ') |> Array.map Int32.Parse
        
    let sets =
        let cardSet = getSet 1 n
        let gateSets =
            List.map getGateSet [1..m]
        cardSet :: gateSets
    
    Set.intersectMany sets
    |> Set.count
    |> printfn "%d"
    
    0