n , m = map(int, input().split())
count = 0
low = 0
high  = n
for _ in range(m):
    l,r=map(int, input().split())
    low = max(l, low)
    high = min(high, r)
    #print(low, high)

print(max(high-low+1, 0)) n , m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m count = 0 count 0 low = 0 low 0 high  = n high n for _ in range(m):
    l,r=map(int, input().split())
    low = max(l, low)
    high = min(high, r)
    #print(low, high) _ range(m) range m l,r=map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split r low = max(l, low) low max(l, low) max l low high = min(high, r) high min(high, r) min high r print(max(high-low+1, 0)) print max(high-low+1, 0) max high-low+1 high-low high low 1 0 m = map(int, input().split()) map(int, input().split()) m low = 0 0 low n , m = map(int, input().split()) map(int, input().split()) n high = min(high, r) min(high, r) high high  = n n high low = max(l, low) max(l, low) low l,r=map(int, input().split()) map(int, input().split()) l count = 0 0 count r=map(int, input().split()) map(int, input().split()) r
n , m = map(int, input().split())
count = 0
low = 0
high  = n
for _ in range(m):
    l,r=map(int, input().split())
    low = max(l, low)
    high = min(high, r)
    #print(low, high)

print(max(high-low+1, 0))