n, m = map(int, input().split())
l, r = 1, 10**5

for i in range(m):
    ll, rr = map(int, input().split())
    l = max(l, ll)
    r = min(r, rr)

if l > r:
    print(0)
else:
    print(r-l+1) n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m l, r = 1, 10**5 l 1 r 10**5 10 5 for i in range(m):
    ll, rr = map(int, input().split())
    l = max(l, ll)
    r = min(r, rr) i range(m) range m ll, rr = map(int, input().split()) ll map(int, input().split()) map int input().split() ().split () input split rr l = max(l, ll) l max(l, ll) max l ll r = min(r, rr) r min(r, rr) min r rr if l > r:
    print(0)
else:
    print(r-l+1) l > r l r print(0) print 0 print(r-l+1) print r-l+1 r-l r l 1 r = 1, 10**5 10**5 r n, m = map(int, input().split()) map(int, input().split()) n l, r = 1, 10**5 1 l rr = map(int, input().split()) map(int, input().split()) rr r = min(r, rr) min(r, rr) r l = max(l, ll) max(l, ll) l ll, rr = map(int, input().split()) map(int, input().split()) ll m = map(int, input().split()) map(int, input().split()) m
n, m = map(int, input().split())
l, r = 1, 10**5

for i in range(m):
    ll, rr = map(int, input().split())
    l = max(l, ll)
    r = min(r, rr)

if l > r:
    print(0)
else:
    print(r-l+1)
