N, M = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(M)]

max_l, min_r = 0, N

for l, r in LR:
    max_l = max(l, max_l)
    min_r = min(r, min_r)
    if min_r < max_l:
        print(0)
        exit()

print(min_r - max_l + 1) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M tuple(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split LR = [tuple(map(int, input().split())) for _ in range(M)] LR [tuple(map(int, input().split())) for _ in range(M)] max_l, min_r = 0, N max_l 0 min_r N for l, r in LR:
    max_l = max(l, max_l)
    min_r = min(r, min_r)
    if min_r < max_l:
        print(0)
        exit() l r LR max_l = max(l, max_l) max_l max(l, max_l) max l max_l min_r = min(r, min_r) min_r min(r, min_r) min r min_r if min_r < max_l:
        print(0)
        exit() min_r < max_l min_r max_l print(0) print 0 exit() exit print(min_r - max_l + 1) print min_r - max_l + 1 min_r - max_l min_r max_l 1 N, M = map(int, input().split()) map(int, input().split()) N max_l, min_r = 0, N 0 max_l min_r = min(r, min_r) min(r, min_r) min_r LR = [tuple(map(int, input().split())) for _ in range(M)] [tuple(map(int, input().split())) for _ in range(M)] LR M = map(int, input().split()) map(int, input().split()) M max_l = max(l, max_l) max(l, max_l) max_l min_r = 0, N N min_r
N, M = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(M)]

max_l, min_r = 0, N

for l, r in LR:
    max_l = max(l, max_l)
    min_r = min(r, min_r)
    if min_r < max_l:
        print(0)
        exit()

print(min_r - max_l + 1)
