
def resolve():
    import sys
    import string
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    n, m = [int(x) for x in input().rstrip().split(" ")]
    left = 1
    right = n
    for i in range(m):
        l, r = [int(x) for x in input().rstrip().split(" ")]
        if left < l:
            left = l
        if right > r:
            right = r

        if right < left:
            print(0)
            return

    print(right - left + 1)


if __name__ == "__main__":
    resolve() def resolve():
    import sys
    import string
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    n, m = [int(x) for x in input().rstrip().split(" ")]
    left = 1
    right = n
    for i in range(m):
        l, r = [int(x) for x in input().rstrip().split(" ")]
        if left < l:
            left = l
        if right > r:
            right = r

        if right < left:
            print(0)
            return

    print(right - left + 1) resolve import sys sys import string string input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline int(x) for x in input().rstrip().split(" ") for x in input().rstrip().split(" ") x input().rstrip().split(" ") ().rstrip().split ().rstrip() ().rstrip () input rstrip split " " for x in input().rstrip().split(" ") int(x) int x n, m = [int(x) for x in input().rstrip().split(" ")] n [int(x) for x in input().rstrip().split(" ")] m left = 1 left 1 right = n right n for i in range(m):
        l, r = [int(x) for x in input().rstrip().split(" ")]
        if left < l:
            left = l
        if right > r:
            right = r

        if right < left:
            print(0)
            return

     i range(m) range m int(x) for x in input().rstrip().split(" ") for x in input().rstrip().split(" ") x input().rstrip().split(" ") ().rstrip().split ().rstrip() ().rstrip () input rstrip split " " for x in input().rstrip().split(" ") int(x) int x l, r = [int(x) for x in input().rstrip().split(" ")] l [int(x) for x in input().rstrip().split(" ")] r if left < l:
            left = l
         left < l left l left = l left l if right > r:
            right = r

         right > r right r right = r right r if right < left:
            print(0)
            return

     right < left right left print(0) print 0 return print(right - left + 1) print right - left + 1 right - left right left 1 if __name__ == "__main__":
    resolve() __name__ == "__main__" __name__ "__main__" resolve() resolve def resolve():
    import sys
    import string
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    n, m = [int(x) for x in input().rstrip().split(" ")]
    left = 1
    right = n
    for i in range(m):
        l, r = [int(x) for x in input().rstrip().split(" ")]
        if left < l:
            left = l
        if right > r:
            right = r

        if right < left:
            print(0)
            return

    print(right - left + 1) def resolve():
    import sys
    import string
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    n, m = [int(x) for x in input().rstrip().split(" ")]
    left = 1
    right = n
    for i in range(m):
        l, r = [int(x) for x in input().rstrip().split(" ")]
        if left < l:
            left = l
        if right > r:
            right = r

        if right < left:
            print(0)
            return

    print(right - left + 1) resolve

def resolve():
    import sys
    import string
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    n, m = [int(x) for x in input().rstrip().split(" ")]
    left = 1
    right = n
    for i in range(m):
        l, r = [int(x) for x in input().rstrip().split(" ")]
        if left < l:
            left = l
        if right > r:
            right = r

        if right < left:
            print(0)
            return

    print(right - left + 1)


if __name__ == "__main__":
    resolve()
