N,M = map(int,input().split())
left = []
right = []
for i in range(M):
    l,r = map(int,input().split())
    left.append(l)
    right.append(r)
if max(left)>min(right):
    print(0)
else:
    print(min(right)-max(left)+1) N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M left = [] left [] right = [] right [] for i in range(M):
    l,r = map(int,input().split())
    left.append(l)
    right.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 left.append(l) left.append left append l right.append(r) right.append right append r if max(left)>min(right):
    print(0)
else:
    print(min(right)-max(left)+1) max(left)>min(right) max(left) max left min(right) min right print(0) print 0 print(min(right)-max(left)+1) print min(right)-max(left)+1 min(right)-max(left) min(right) min right max(left) max left 1 M = map(int,input().split()) map(int,input().split()) M right = [] [] right r = map(int,input().split()) map(int,input().split()) r left = [] [] left l,r = map(int,input().split()) map(int,input().split()) l N,M = map(int,input().split()) map(int,input().split()) N
N,M = map(int,input().split())
left = []
right = []
for i in range(M):
    l,r = map(int,input().split())
    left.append(l)
    right.append(r)
if max(left)>min(right):
    print(0)
else:
    print(min(right)-max(left)+1)