#n=int(input())
#s,t=input().split()
n,m = map(int, input().split())
#l=list(map(int, input().split()))
l=[0]*100005
r=[1000005]*100005
z=1000010
for i in range(m):
   l[i],r[i]=map(int,input().split()) 
mi=max(l)
ma=min(r)



if mi>ma:
    print(0)
else:
    print(ma-mi+1) n,m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l=[0]*100005 l [0]*100005 [0] 0 100005 r=[1000005]*100005 r [1000005]*100005 [1000005] 1000005 100005 z=1000010 z 1000010 for i in range(m):
   l[i],r[i]=map(int,input().split())  i range(m) range m l[i],r[i]=map(int,input().split()) l[i] l i map(int,input().split()) map int input().split() ().split () input split r[i] r i mi=max(l) mi max(l) max l ma=min(r) ma min(r) min r if mi>ma:
    print(0)
else:
    print(ma-mi+1) mi>ma mi ma print(0) print 0 print(ma-mi+1) print ma-mi+1 ma-mi ma mi 1 z=1000010 1000010 z mi=max(l) max(l) mi r=[1000005]*100005 [1000005]*100005 r n,m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m ma=min(r) min(r) ma l=[0]*100005 [0]*100005 l
#n=int(input())
#s,t=input().split()
n,m = map(int, input().split())
#l=list(map(int, input().split()))
l=[0]*100005
r=[1000005]*100005
z=1000010
for i in range(m):
   l[i],r[i]=map(int,input().split()) 
mi=max(l)
ma=min(r)



if mi>ma:
    print(0)
else:
    print(ma-mi+1)