import collections

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

r = []

l = []

for i in range(m):

    ll,rr = list(map(int,input().split()))

    r.append(rr)

    l.append(ll)

ans = min(r) - max(l) +1

if ans > 0:

    print(ans)

else :

    print((0))
from collections import Counter,defaultdict

import sys,heapq,bisect,math,itertools,string,queue

mod = 10**9+7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())



n,m = inpl()

cnt = [0]*(n+1)

for i in range(m):

    l,r = inpl()

    cnt[l-1] += 1

    cnt[r] -= 1

cntsum = list(itertools.accumulate(cnt))

print((cntsum.count(m)))
import collections

n, m = list(map(int, input().split()))
r = []
l = []
for i in range(m):
    ll, rr = list(map(int, input().split()))
    r.append(rr)
    l.append(ll)
ans = min(r) - max(l) + 1
if ans > 0:
    print(ans)
else:
    print((0))

from collections import Counter, defaultdict
import sys, heapq, bisect, math, itertools, string, queue

mod = 10**9 + 7


def inp():
    return int(sys.stdin.readline())


def inpl():
    return list(map(int, sys.stdin.readline().split()))


def inpl_str():
    return list(sys.stdin.readline().split())


n, m = inpl()
cnt = [0] * (n + 1)
for i in range(m):
    l, r = inpl()
    cnt[l - 1] += 1
    cnt[r] -= 1
cntsum = list(itertools.accumulate(cnt))
print((cntsum.count(m)))

-import collections +from collections import Counter, defaultdict +import sys, heapq, bisect, math, itertools, string, queue -n, m = list(map(int, input().split())) -r = [] -l = [] +mod = 10**9 + 7 + + +def inp(): +    return int(sys.stdin.readline()) + + +def inpl(): +    return list(map(int, sys.stdin.readline().split())) + + +def inpl_str(): +    return list(sys.stdin.readline().split()) + + +n, m = inpl() +cnt = [0] * (n + 1) -    ll, rr = list(map(int, input().split())) -    r.append(rr) -    l.append(ll) -ans = min(r) - max(l) + 1 -if ans > 0: -    print(ans) -else: -    print((0)) +    l, r = inpl() +    cnt[l - 1] += 1 +    cnt[r] -= 1 +cntsum = list(itertools.accumulate(cnt)) +print((cntsum.count(m)))