n,a = list(map(int,input().split()))

m = [tuple(map(int,input().split())) for _ in range(a)]



l,r=m[0][0],m[0][1]



for i in range(1,a):

    l = max(m[i][0],l)

    r = min(m[i][1],r)



print((max(r-l+1,0)))

import sys

sys.setrecursionlimit(10000000)

input=sys.stdin.readline



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



ansl=-1

ansr=10**6



for _ in range(m):

    l,r=list(map(int,input().split()))

    ansl=max(ansl,l)

    ansr=min(ansr,r)



print((max(ansr-ansl+1,0)))
n, a = list(map(int, input().split()))
m = [tuple(map(int, input().split())) for _ in range(a)]
l, r = m[0][0], m[0][1]
for i in range(1, a):
    l = max(m[i][0], l)
    r = min(m[i][1], r)
print((max(r - l + 1, 0)))

import sys

sys.setrecursionlimit(10000000)
input = sys.stdin.readline
n, m = list(map(int, input().split()))
ansl = -1
ansr = 10**6
for _ in range(m):
    l, r = list(map(int, input().split()))
    ansl = max(ansl, l)
    ansr = min(ansr, r)
print((max(ansr - ansl + 1, 0)))

-n, a = list(map(int, input().split())) -m = [tuple(map(int, input().split())) for _ in range(a)] -l, r = m[0][0], m[0][1] -for i in range(1, a): -    l = max(m[i][0], l) -    r = min(m[i][1], r) -print((max(r - l + 1, 0))) +import sys + +sys.setrecursionlimit(10000000) +input = sys.stdin.readline +n, m = list(map(int, input().split())) +ansl = -1 +ansr = 10**6 +for _ in range(m): +    l, r = list(map(int, input().split())) +    ansl = max(ansl, l) +    ansr = min(ansr, r) +print((max(ansr - ansl + 1, 0)))