n, m = map(int, input().split())
inf = 0
sup = 100001
for i in range(m) :
    l, r = map(int, input().split())
    inf = max(inf, l)
    sup = min(sup, r)
if sup >= inf :
    print(sup-inf+1)
else :
    print("0") n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m inf = 0 inf 0 sup = 100001 sup 100001 for i in range(m) :
    l, r = map(int, input().split())
    inf = max(inf, l)
    sup = min(sup, r) i range(m) range m l, r = map(int, input().split()) l map(int, input().split()) map int input().split() ().split () input split r inf = max(inf, l) inf max(inf, l) max inf l sup = min(sup, r) sup min(sup, r) min sup r if sup >= inf :
    print(sup-inf+1)
else :
    print("0") sup >= inf sup inf print(sup-inf+1) print sup-inf+1 sup-inf sup inf 1 print("0") print "0" r = map(int, input().split()) map(int, input().split()) r inf = 0 0 inf l, r = map(int, input().split()) map(int, input().split()) l inf = max(inf, l) max(inf, l) inf sup = min(sup, r) min(sup, r) sup n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m sup = 100001 100001 sup
n, m = map(int, input().split())
inf = 0
sup = 100001
for i in range(m) :
    l, r = map(int, input().split())
    inf = max(inf, l)
    sup = min(sup, r)
if sup >= inf :
    print(sup-inf+1)
else :
    print("0")
