n,m = map(int,input().split())
l = [0] * m
r = [0] * m
l_max = 1
r_min = n
for i in range(m):
    l[i], r[i] = map(int,input().split())
    l_max = max(l[i],l_max)
    r_min = min(r[i], r_min)
if r_min >= l_max:
    print(r_min - l_max + 1)
else:
    print(0) n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l = [0] * m l [0] * m [0] 0 m r = [0] * m r [0] * m [0] 0 m l_max = 1 l_max 1 r_min = n r_min n for i in range(m):
    l[i], r[i] = map(int,input().split())
    l_max = max(l[i],l_max)
    r_min = min(r[i], r_min) i range(m) range m l[i], r[i] = map(int,input().split()) l[i] l i map(int,input().split()) map int input().split() ().split () input split r[i] r i l_max = max(l[i],l_max) l_max max(l[i],l_max) max l[i] l i l_max r_min = min(r[i], r_min) r_min min(r[i], r_min) min r[i] r i r_min if r_min >= l_max:
    print(r_min - l_max + 1)
else:
    print(0) r_min >= l_max r_min l_max print(r_min - l_max + 1) print r_min - l_max + 1 r_min - l_max r_min l_max 1 print(0) print 0 r_min = min(r[i], r_min) min(r[i], r_min) r_min l = [0] * m [0] * m l l_max = max(l[i],l_max) max(l[i],l_max) l_max r_min = n n r_min n,m = map(int,input().split()) map(int,input().split()) n m = map(int,input().split()) map(int,input().split()) m l_max = 1 1 l_max r = [0] * m [0] * m r
n,m = map(int,input().split())
l = [0] * m
r = [0] * m
l_max = 1
r_min = n
for i in range(m):
    l[i], r[i] = map(int,input().split())
    l_max = max(l[i],l_max)
    r_min = min(r[i], r_min)
if r_min >= l_max:
    print(r_min - l_max + 1)
else:
    print(0)