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



l_max=-1

r_min=float("inf")

for i in range(M):

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

	l_max=max(l_max, l)

	r_min=min(r_min, r)



if r_min<l_max:

	print(0)

else:

	print(r_min-l_max+1)
import sys

N,M=list(map(int, sys.stdin.readline().split()))

ll=float("-inf")

rr=float("inf")

for _ in range(M):

    l,r=list(map(int, sys.stdin.readline().split()))

    ll=max(ll,l)

    rr=min(rr,r)



if ll<=rr:

    print(rr-ll+1)

else:

    print(0)
N, M = list(map(int, input().split()))
l_max = -1
r_min = float("inf")
for i in range(M):
    l, r = list(map(int, input().split()))
    l_max = max(l_max, l)
    r_min = min(r_min, r)
if r_min < l_max:
    print(0)
else:
    print(r_min - l_max + 1)

import sys

N, M = list(map(int, sys.stdin.readline().split()))
ll = float("-inf")
rr = float("inf")
for _ in range(M):
    l, r = list(map(int, sys.stdin.readline().split()))
    ll = max(ll, l)
    rr = min(rr, r)
if ll <= rr:
    print(rr - ll + 1)
else:
    print(0)

-N, M = list(map(int, input().split())) -l_max = -1 -r_min = float("inf") -for i in range(M): -    l, r = list(map(int, input().split())) -    l_max = max(l_max, l) -    r_min = min(r_min, r) -if r_min < l_max: +import sys + +N, M = list(map(int, sys.stdin.readline().split())) +ll = float("-inf") +rr = float("inf") +for _ in range(M): +    l, r = list(map(int, sys.stdin.readline().split())) +    ll = max(ll, l) +    rr = min(rr, r) +if ll <= rr: +    print(rr - ll + 1) +else: -else: -    print(r_min - l_max + 1)