n, m = map(int, input().strip().split())

max_left = 0
min_right = n
for _ in range(m):
    l_tmp, r_tmp = map(int, input().strip().split())
    if max_left < l_tmp:
        max_left = l_tmp
    if r_tmp < min_right:
        min_right = r_tmp

if min_right < max_left:
    print(0)
else:
    print(min_right - max_left + 1) n, m = map(int, input().strip().split()) n map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split m max_left = 0 max_left 0 min_right = n min_right n for _ in range(m):
    l_tmp, r_tmp = map(int, input().strip().split())
    if max_left < l_tmp:
        max_left = l_tmp
    if r_tmp < min_right:
        min_right = r_tmp _ range(m) range m l_tmp, r_tmp = map(int, input().strip().split()) l_tmp map(int, input().strip().split()) map int input().strip().split() ().strip().split ().strip() ().strip () input strip split r_tmp if max_left < l_tmp:
        max_left = l_tmp
     max_left < l_tmp max_left l_tmp max_left = l_tmp max_left l_tmp if r_tmp < min_right:
        min_right = r_tmp r_tmp < min_right r_tmp min_right min_right = r_tmp min_right r_tmp if min_right < max_left:
    print(0)
else:
    print(min_right - max_left + 1) min_right < max_left min_right max_left print(0) print 0 print(min_right - max_left + 1) print min_right - max_left + 1 min_right - max_left min_right max_left 1 n, m = map(int, input().strip().split()) map(int, input().strip().split()) n max_left = 0 0 max_left l_tmp, r_tmp = map(int, input().strip().split()) map(int, input().strip().split()) l_tmp r_tmp = map(int, input().strip().split()) map(int, input().strip().split()) r_tmp max_left = l_tmp l_tmp max_left min_right = r_tmp r_tmp min_right min_right = n n min_right m = map(int, input().strip().split()) map(int, input().strip().split()) m
n, m = map(int, input().strip().split())

max_left = 0
min_right = n
for _ in range(m):
    l_tmp, r_tmp = map(int, input().strip().split())
    if max_left < l_tmp:
        max_left = l_tmp
    if r_tmp < min_right:
        min_right = r_tmp

if min_right < max_left:
    print(0)
else:
    print(min_right - max_left + 1)
