n,m=map(int,input().split())
L=[]
R=[]
for i in range(m):
    l,r=map(int,input().split())
    L.append(l)
    R.append(r)
LL=max(L)
RR=min(R)
if LL<=RR:
    print(RR-LL+1)
else:
    print(0) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m L=[] L [] R=[] R [] for i in range(m):
    l,r=map(int,input().split())
    L.append(l)
    R.append(r) i range(m) range m l,r=map(int,input().split()) l map(int,input().split()) map int input().split() ().split () input split r L.append(l) L.append L append l R.append(r) R.append R append r LL=max(L) LL max(L) max L RR=min(R) RR min(R) min R if LL<=RR:
    print(RR-LL+1)
else:
    print(0) LL<=RR LL RR print(RR-LL+1) print RR-LL+1 RR-LL RR LL 1 print(0) print 0 RR=min(R) min(R) RR R=[] [] R L=[] [] L LL=max(L) max(L) LL m=map(int,input().split()) map(int,input().split()) m r=map(int,input().split()) map(int,input().split()) r n,m=map(int,input().split()) map(int,input().split()) n l,r=map(int,input().split()) map(int,input().split()) l
n,m=map(int,input().split())
L=[]
R=[]
for i in range(m):
    l,r=map(int,input().split())
    L.append(l)
    R.append(r)
LL=max(L)
RR=min(R)
if LL<=RR:
    print(RR-LL+1)
else:
    print(0)