#C - Prison(ABC127)

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

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

for i in range(M-1):

    L,R=list(map(int,input().split()))

    l=max(L,l)

    r=min(r,R)

if r-l+1>0:

    print((r-l+1))

else:

    print((0))
#C - Prison(ABC127)

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

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

for i in range(M-1):

    L,R=list(map(int,input().split()))

    if l<L:

        l=L

    if r>R:

        r=R

if r-l+1>0:

    print((r-l+1))

else:

    print((0))
# C - Prison(ABC127)
N, M = list(map(int, input().split()))
l, r = list(map(int, input().split()))
for i in range(M - 1):
    L, R = list(map(int, input().split()))
    l = max(L, l)
    r = min(r, R)
if r - l + 1 > 0:
    print((r - l + 1))
else:
    print((0))

# C - Prison(ABC127)
N, M = list(map(int, input().split()))
l, r = list(map(int, input().split()))
for i in range(M - 1):
    L, R = list(map(int, input().split()))
    if l < L:
        l = L
    if r > R:
        r = R
if r - l + 1 > 0:
    print((r - l + 1))
else:
    print((0))

-    l = max(L, l) -    r = min(r, R) +    if l < L: +        l = L +    if r > R: +        r = R