Module _20190525

    Sub Main()

        Dim sRead As String = Console.ReadLine()
        Dim N As Integer = sRead.Split(" ")(0)
        Dim M As Integer = sRead.Split(" ")(1)

        Dim sFirst As String = Console.ReadLine()

        Dim iMin As Integer = sFirst.Split(" ")(0)
        Dim iMax As Integer = sFirst.Split(" ")(1)

        For i As Integer = 2 To M

            Dim sTemp As String = Console.ReadLine()

            If CInt(sTemp.Split(" ")(0)) > iMin Then

                iMin = CInt(sTemp.Split(" ")(0))

            End If

            If CInt(sTemp.Split(" ")(1)) < iMax Then

                iMax = CInt(sTemp.Split(" ")(1))

            End If

        Next

        Console.WriteLine(iMax - iMin + 1)

    End Sub

End Module
