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

l_ans = 0
r_ans = float('inf')
for l, r in l_r:
    l_ans = max(l_ans, l)
    r_ans = min(r_ans, r)
if r_ans < l_ans:
    ans = 0
else:
    ans = r_ans-l_ans+1
print(ans)  n, m = map(int, input().split()) n 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 l_r = [ list(map(int, input().split())) for _ in range(m) ] l_r [ list(map(int, input().split())) for _ in range(m) ] l_ans = 0 l_ans 0 r_ans = float('inf') r_ans float('inf') float 'inf' for l, r in l_r:
    l_ans = max(l_ans, l)
    r_ans = min(r_ans, r) l r l_r l_ans = max(l_ans, l) l_ans max(l_ans, l) max l_ans l r_ans = min(r_ans, r) r_ans min(r_ans, r) min r_ans r if r_ans < l_ans:
    ans = 0
else:
    ans = r_ans-l_ans+1 r_ans < l_ans r_ans l_ans ans = 0 ans 0 ans = r_ans-l_ans+1 ans r_ans-l_ans+1 r_ans-l_ans r_ans l_ans 1 print(ans) print ans n, m = map(int, input().split()) map(int, input().split()) n l_ans = max(l_ans, l) max(l_ans, l) l_ans ans = 0 0 ans ans = r_ans-l_ans+1 r_ans-l_ans+1 ans l_r = [ list(map(int, input().split())) for _ in range(m) ] [ list(map(int, input().split())) for _ in range(m) ] l_r r_ans = min(r_ans, r) min(r_ans, r) r_ans m = map(int, input().split()) map(int, input().split()) m l_ans = 0 0 l_ans r_ans = float('inf') float('inf') r_ans
n, m = map(int, input().split())
l_r = [ list(map(int, input().split())) for _ in range(m) ]

l_ans = 0
r_ans = float('inf')
for l, r in l_r:
    l_ans = max(l_ans, l)
    r_ans = min(r_ans, r)
if r_ans < l_ans:
    ans = 0
else:
    ans = r_ans-l_ans+1
print(ans) 