L,M=map(int,input().split())
a=[0]*L
x=[]
y=[]
for i in range(M):
    b,c=map(int,input().split())
    x.append(b)
    y.append(c)
if max(x)<=min(y):
    print(-max(x)+min(y)+1)
else:
    print(0) L,M=map(int,input().split()) L map(int,input().split()) map int input().split() ().split () input split M a=[0]*L a [0]*L [0] 0 L x=[] x [] y=[] y [] for i in range(M):
    b,c=map(int,input().split())
    x.append(b)
    y.append(c) i range(M) range M b,c=map(int,input().split()) b map(int,input().split()) map int input().split() ().split () input split c x.append(b) x.append x append b y.append(c) y.append y append c if max(x)<=min(y):
    print(-max(x)+min(y)+1)
else:
    print(0) max(x)<=min(y) max(x) max x min(y) min y print(-max(x)+min(y)+1) print -max(x)+min(y)+1 -max(x)+min(y) -max(x) max(x) max x min(y) min y 1 print(0) print 0 L,M=map(int,input().split()) map(int,input().split()) L x=[] [] x c=map(int,input().split()) map(int,input().split()) c a=[0]*L [0]*L a y=[] [] y b,c=map(int,input().split()) map(int,input().split()) b M=map(int,input().split()) map(int,input().split()) M
L,M=map(int,input().split())
a=[0]*L
x=[]
y=[]
for i in range(M):
    b,c=map(int,input().split())
    x.append(b)
    y.append(c)
if max(x)<=min(y):
    print(-max(x)+min(y)+1)
else:
    print(0)