# 先頭の最大と最後尾の最小を求める
card_num, gate_num = map(int, input().split())
lmax, rmin = map(int, input().split()) # 最初の入力がlの最大とrの最小
for i in range(1, gate_num):
    l, r = map(int, input().split())
    lmax = max(lmax, l) # lmaxにlmaxとlの大きい方
    rmin = min(rmin, r) # rminにrminとrの小さい方
print(max(0, rmin-lmax+1)) # 0かrmin-lmax+1の大きい方を出力 card_num, gate_num = map(int, input().split()) card_num map(int, input().split()) map int input().split() ().split () input split gate_num lmax, rmin = map(int, input().split()) lmax map(int, input().split()) map int input().split() ().split () input split rmin for i in range(1, gate_num):
    l, r = map(int, input().split())
    lmax = max(lmax, l) # lmaxにlmaxとlの大きい方
    rmin = min(rmin, r) # rminにrminとrの小さい方 i range(1, gate_num) range 1 gate_num l, r = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split r lmax = max(lmax, l) lmax max(lmax, l) max lmax l rmin = min(rmin, r) rmin min(rmin, r) min rmin r print(max(0, rmin-lmax+1)) print max(0, rmin-lmax+1) max 0 rmin-lmax+1 rmin-lmax rmin lmax 1 l, r = map(int, input().split()) map(int, input().split()) l lmax = max(lmax, l) max(lmax, l) lmax card_num, gate_num = map(int, input().split()) map(int, input().split()) card_num r = map(int, input().split()) map(int, input().split()) r lmax, rmin = map(int, input().split()) map(int, input().split()) lmax rmin = min(rmin, r) min(rmin, r) rmin rmin = map(int, input().split()) map(int, input().split()) rmin gate_num = map(int, input().split()) map(int, input().split()) gate_num
# 先頭の最大と最後尾の最小を求める
card_num, gate_num = map(int, input().split())
lmax, rmin = map(int, input().split()) # 最初の入力がlの最大とrの最小
for i in range(1, gate_num):
    l, r = map(int, input().split())
    lmax = max(lmax, l) # lmaxにlmaxとlの大きい方
    rmin = min(rmin, r) # rminにrminとrの小さい方
print(max(0, rmin-lmax+1)) # 0かrmin-lmax+1の大きい方を出力