n,m = map(int,input().split(' '))
l = []
start = 0
end = n+1
count = 0

for i in range(m):
    l.append(list(map(int,input().split(' '))))

for i in l:
    if i[0] >= start:
        start = i[0]
    if i[1] <= end:
        end = i[1]
if start > end:
    print(0)
else:
    print(end-start+1) n,m = map(int,input().split(' ')) n map(int,input().split(' ')) map int input().split(' ') ().split () input split ' ' m l = [] l [] start = 0 start 0 end = n+1 end n+1 n 1 count = 0 count 0 for i in range(m):
    l.append(list(map(int,input().split(' ')))) i range(m) range m l.append(list(map(int,input().split(' ')))) l.append l append list(map(int,input().split(' '))) list map(int,input().split(' ')) map int input().split(' ') ().split () input split ' ' for i in l:
    if i[0] >= start:
        start = i[0]
    if i[1] <= end:
        end = i[1] i l if i[0] >= start:
        start = i[0]
     i[0] >= start i[0] i 0 start start = i[0] start i[0] i 0 if i[1] <= end:
        end = i[1] i[1] <= end i[1] i 1 end end = i[1] end i[1] i 1 if start > end:
    print(0)
else:
    print(end-start+1) start > end start end print(0) print 0 print(end-start+1) print end-start+1 end-start end start 1 n,m = map(int,input().split(' ')) map(int,input().split(' ')) n start = i[0] i[0] start m = map(int,input().split(' ')) map(int,input().split(' ')) m start = 0 0 start count = 0 0 count end = i[1] i[1] end l = [] [] l end = n+1 n+1 end
n,m = map(int,input().split(' '))
l = []
start = 0
end = n+1
count = 0

for i in range(m):
    l.append(list(map(int,input().split(' '))))

for i in l:
    if i[0] >= start:
        start = i[0]
    if i[1] <= end:
        end = i[1]
if start > end:
    print(0)
else:
    print(end-start+1)