n,m = map(int,input().split())
l,r = [],[]
for i in range(m):
    a,b = map(int,input().split())
    l.append(a)
    r.append(b)
num = list(range(1,n+1))
lmax = max(l)
rmin = min(r)
if lmax > rmin:
    print(0)
else:
    gate = set(range(lmax,rmin+1))
    ans = list(set(num) & gate)
    print(len(ans)) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l,r = [],[] l [] r [] for i in range(m):
    a,b = map(int,input().split())
    l.append(a)
    r.append(b) i range(m) range m a,b = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b l.append(a) l.append l append a r.append(b) r.append r append b num = list(range(1,n+1)) num list(range(1,n+1)) list range(1,n+1) range 1 n+1 n 1 lmax = max(l) lmax max(l) max l rmin = min(r) rmin min(r) min r if lmax > rmin:
    print(0)
else:
    gate = set(range(lmax,rmin+1))
    ans = list(set(num) & gate)
    print(len(ans)) lmax > rmin lmax rmin print(0) print 0 gate = set(range(lmax,rmin+1)) gate set(range(lmax,rmin+1)) set range(lmax,rmin+1) range lmax rmin+1 rmin 1 ans = list(set(num) & gate) ans list(set(num) & gate) list set(num) & gate set(num) set num gate print(len(ans)) print len(ans) len ans n,m = map(int,input().split()) map(int,input().split()) n lmax = max(l) max(l) lmax gate = set(range(lmax,rmin+1)) set(range(lmax,rmin+1)) gate l,r = [],[] [] l b = map(int,input().split()) map(int,input().split()) b rmin = min(r) min(r) rmin a,b = map(int,input().split()) map(int,input().split()) a num = list(range(1,n+1)) list(range(1,n+1)) num m = map(int,input().split()) map(int,input().split()) m r = [],[] [] r ans = list(set(num) & gate) list(set(num) & gate) ans
n,m = map(int,input().split())
l,r = [],[]
for i in range(m):
    a,b = map(int,input().split())
    l.append(a)
    r.append(b)
num = list(range(1,n+1))
lmax = max(l)
rmin = min(r)
if lmax > rmin:
    print(0)
else:
    gate = set(range(lmax,rmin+1))
    ans = list(set(num) & gate)
    print(len(ans))