# import math
# import statistics
# a=input()
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(i)
e1,e2 = map(int,input().split())
#f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
h = []
for i in range(e2):
    h.append(list(map(int,input().split())))
L=[]
R=[]
for i in range(len(h)):
    L.append(h[i][0])
for i in range(len(h)):
    R.append(h[i][1])

if min(R)>=max(L):
    print(min(R)-max(L)+1)
else:
    print(0)

 e1,e2 = map(int,input().split()) e1 map(int,input().split()) map int input().split() ().split () input split e2 h = [] h [] for i in range(e2):
    h.append(list(map(int,input().split()))) i range(e2) range e2 h.append(list(map(int,input().split()))) h.append h append list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split L=[] L [] R=[] R [] for i in range(len(h)):
    L.append(h[i][0]) i range(len(h)) range len(h) len h L.append(h[i][0]) L.append L append h[i][0] [i] h i 0 for i in range(len(h)):
    R.append(h[i][1]) i range(len(h)) range len(h) len h R.append(h[i][1]) R.append R append h[i][1] [i] h i 1 if min(R)>=max(L):
    print(min(R)-max(L)+1)
else:
    print(0) min(R)>=max(L) min(R) min R max(L) max L print(min(R)-max(L)+1) print min(R)-max(L)+1 min(R)-max(L) min(R) min R max(L) max L 1 print(0) print 0 h = [] [] h e2 = map(int,input().split()) map(int,input().split()) e2 L=[] [] L R=[] [] R e1,e2 = map(int,input().split()) map(int,input().split()) e1
# import math
# import statistics
# a=input()
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(i)
e1,e2 = map(int,input().split())
#f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
h = []
for i in range(e2):
    h.append(list(map(int,input().split())))
L=[]
R=[]
for i in range(len(h)):
    L.append(h[i][0])
for i in range(len(h)):
    R.append(h[i][1])

if min(R)>=max(L):
    print(min(R)-max(L)+1)
else:
    print(0)


