N,M = list(map(int,input().split()))

A = []

B = []

for _ in range(M):

    temp = list(map(int,input().split()))

    A.append(temp[0])

    B.append(temp[1])

cnt = 0

minA = max(A)

maxA = min(B)

if maxA - minA + 1 > 0:

    print((maxA - minA + 1))

else:

    print((0))

        
import sys

input = lambda : sys.stdin.readline().rstrip()



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



left = -1

right = n + 1



for _ in range(m):

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

    if r < left or l > right:

        print((0))

        sys.exit()

    left = max(left, l)

    right = min(right, r)



print((right - left + 1))
N, M = list(map(int, input().split()))
A = []
B = []
for _ in range(M):
    temp = list(map(int, input().split()))
    A.append(temp[0])
    B.append(temp[1])
cnt = 0
minA = max(A)
maxA = min(B)
if maxA - minA + 1 > 0:
    print((maxA - minA + 1))
else:
    print((0))

import sys

input = lambda: sys.stdin.readline().rstrip()
n, m = list(map(int, input().split()))
left = -1
right = n + 1
for _ in range(m):
    l, r = list(map(int, input().split()))
    if r < left or l > right:
        print((0))
        sys.exit()
    left = max(left, l)
    right = min(right, r)
print((right - left + 1))

-N, M = list(map(int, input().split())) -A = [] -B = [] -for _ in range(M): -    temp = list(map(int, input().split())) -    A.append(temp[0]) -    B.append(temp[1]) -cnt = 0 -minA = max(A) -maxA = min(B) -if maxA - minA + 1 > 0: -    print((maxA - minA + 1)) -else: -    print((0)) +import sys + +input = lambda: sys.stdin.readline().rstrip() +n, m = list(map(int, input().split())) +left = -1 +right = n + 1 +for _ in range(m): +    l, r = list(map(int, input().split())) +    if r < left or l > right: +        print((0)) +        sys.exit() +    left = max(left, l) +    right = min(right, r) +print((right - left + 1))