l, m = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(m)]

ll, rr = 1, l
for l, r in lr:
    if ll <= l <= rr or l <= ll <= r:
        ll, rr = max(ll, l), min(rr, r)
    else:
        print(0)
        exit()
print(rr-ll+1) l, m = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split m list(map(int, input().split())) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split lr = [list(map(int, input().split())) for _ in range(m)] lr [list(map(int, input().split())) for _ in range(m)] ll, rr = 1, l ll 1 rr l for l, r in lr:
    if ll <= l <= rr or l <= ll <= r:
        ll, rr = max(ll, l), min(rr, r)
    else:
        print(0)
        exit() l r lr if ll <= l <= rr or l <= ll <= r:
        ll, rr = max(ll, l), min(rr, r)
    else:
        print(0)
        exit() ll <= l <= rr or l <= ll <= r ll <= l <= rr ll <= l ll l rr l <= ll <= r l <= ll l ll r ll, rr = max(ll, l), min(rr, r) ll max(ll, l) max ll l rr min(rr, r) min rr r print(0) print 0 exit() exit print(rr-ll+1) print rr-ll+1 rr-ll rr ll 1 m = map(int, input().split()) map(int, input().split()) m rr = 1, l l rr l, m = map(int, input().split()) map(int, input().split()) l ll, rr = 1, l 1 ll lr = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] lr rr = max(ll, l), min(rr, r) min(rr, r) rr ll, rr = max(ll, l), min(rr, r) max(ll, l) ll
l, m = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(m)]

ll, rr = 1, l
for l, r in lr:
    if ll <= l <= rr or l <= ll <= r:
        ll, rr = max(ll, l), min(rr, r)
    else:
        print(0)
        exit()
print(rr-ll+1)