#!/usr/bin/env python3
(n, m,), *g = [[*map(int, i.split())] for i in open(0)]
ma = n
mi = 0
for l, r in g:
    mi = max(mi, l)
    ma = min(ma, r)

print(max(ma-mi+1,0)) [*map(int, i.split())] for i in open(0) for i in open(0) i open(0) open 0 for i in open(0) [*map(int, i.split())] *map(int, i.split()) map(int, i.split()) map int i.split() i.split i split (n, m,), *g = [[*map(int, i.split())] for i in open(0)] (n, m,) n m [[*map(int, i.split())] for i in open(0)] *g g ma = n ma n mi = 0 mi 0 for l, r in g:
    mi = max(mi, l)
    ma = min(ma, r) l r g mi = max(mi, l) mi max(mi, l) max mi l ma = min(ma, r) ma min(ma, r) min ma r print(max(ma-mi+1,0)) print max(ma-mi+1,0) max ma-mi+1 ma-mi ma mi 1 0 mi = 0 0 mi mi = max(mi, l) max(mi, l) mi ma = n n ma ma = min(ma, r) min(ma, r) ma
#!/usr/bin/env python3
(n, m,), *g = [[*map(int, i.split())] for i in open(0)]
ma = n
mi = 0
for l, r in g:
    mi = max(mi, l)
    ma = min(ma, r)

print(max(ma-mi+1,0))
