open System

let getIntLine() = Console.ReadLine().Split(' ') |> Array.map Int32.Parse

let getSet l r = Set.ofList [ l..r ]
let getGateSet _ =
    let [| l; r |] = getIntLine()
    getSet l r

[<EntryPoint>]
let main _ =
    let [| n; m |] = getIntLine()

    let sets =
        let cardSet = getSet 1 n
        let gateSets = List.map getGateSet [ 1..m ]
        cardSet :: gateSets

    Set.intersectMany sets
    |> Set.count
    |> printfn "%d"

    0
