def slove():

    import sys

    input = sys.stdin.readline

    n, m = list(map(int, input().rstrip('\n').split()))

    lr = [list(map(int, input().rstrip('\n').split())) for _ in range(m)]

    a = [0] * (n + 2)

    for l, r in lr:

        a[l] += 1

        a[r + 1] -= 1

    t = 0

    cnt = 0

    for i in range(1, n + 1):

        t += a[i]

        if t == m:

            cnt += 1

    print(cnt)





if __name__ == '__main__':

    slove()

def slove():

    import sys

    input = sys.stdin.readline

    n, m = list(map(int, input().rstrip('\n').split()))

    x = [0] * (n + 2)

    for i in range(m):

        l, r = list(map(int, input().rstrip('\n').split()))

        x[l] += 1

        x[r+1] -= 1

    t = 0

    cnt = 0

    for i in range(n + 2):

        t += x[i]

        if t == m:

            cnt += 1

    print(cnt)





if __name__ == '__main__':

    slove()

def slove():
    import sys

    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip("\n").split()))
    lr = [list(map(int, input().rstrip("\n").split())) for _ in range(m)]
    a = [0] * (n + 2)
    for l, r in lr:
        a[l] += 1
        a[r + 1] -= 1
    t = 0
    cnt = 0
    for i in range(1, n + 1):
        t += a[i]
        if t == m:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    slove()

def slove():
    import sys

    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip("\n").split()))
    x = [0] * (n + 2)
    for i in range(m):
        l, r = list(map(int, input().rstrip("\n").split()))
        x[l] += 1
        x[r + 1] -= 1
    t = 0
    cnt = 0
    for i in range(n + 2):
        t += x[i]
        if t == m:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    slove()

-    lr = [list(map(int, input().rstrip("\n").split())) for _ in range(m)] -    a = [0] * (n + 2) -    for l, r in lr: -        a[l] += 1 -        a[r + 1] -= 1 +    x = [0] * (n + 2) +    for i in range(m): +        l, r = list(map(int, input().rstrip("\n").split())) +        x[l] += 1 +        x[r + 1] -= 1 -    for i in range(1, n + 1): -        t += a[i] +    for i in range(n + 2): +        t += x[i]