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)

a = 1
b = N

for i in range(M):
    if(L[i] >= a and R[i] >= b):
        a = L[i]
    if(L[i] <= a and R[i] <= b):
        b = R[i]
    if(L[i] >= a and R[i] <= b):
        a = L[i]
        b = R[i]
    if(R[i] < a or L[i] > b):
        print(0)
        exit()


print(b-a+1) 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 a = 1 a 1 b = N b N for i in range(M):
    if(L[i] >= a and R[i] >= b):
        a = L[i]
    if(L[i] <= a and R[i] <= b):
        b = R[i]
    if(L[i] >= a and R[i] <= b):
        a = L[i]
        b = R[i]
    if(R[i] < a or L[i] > b):
        print(0)
        exit() i range(M) range M if(L[i] >= a and R[i] >= b):
        a = L[i]
     L[i] >= a and R[i] >= b L[i] >= a L[i] L i a R[i] >= b R[i] R i b a = L[i] a L[i] L i if(L[i] <= a and R[i] <= b):
        b = R[i]
     L[i] <= a and R[i] <= b L[i] <= a L[i] L i a R[i] <= b R[i] R i b b = R[i] b R[i] R i if(L[i] >= a and R[i] <= b):
        a = L[i]
        b = R[i]
     L[i] >= a and R[i] <= b L[i] >= a L[i] L i a R[i] <= b R[i] R i b a = L[i] a L[i] L i b = R[i] b R[i] R i if(R[i] < a or L[i] > b):
        print(0)
        exit() R[i] < a or L[i] > b R[i] < a R[i] R i a L[i] > b L[i] L i b print(0) print 0 exit() exit print(b-a+1) print b-a+1 b-a b a 1 N,M = map(int,input().split()) map(int,input().split()) N r = map(int,input().split()) map(int,input().split()) r a = L[i] L[i] a L = [] [] L b = N N b M = map(int,input().split()) map(int,input().split()) M R = [] [] R a = 1 1 a l,r = map(int,input().split()) map(int,input().split()) l a = L[i] L[i] a b = R[i] R[i] b b = R[i] R[i] b
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)

a = 1
b = N

for i in range(M):
    if(L[i] >= a and R[i] >= b):
        a = L[i]
    if(L[i] <= a and R[i] <= b):
        b = R[i]
    if(L[i] >= a and R[i] <= b):
        a = L[i]
        b = R[i]
    if(R[i] < a or L[i] > b):
        print(0)
        exit()


print(b-a+1)