N,M = (int(x) for x in input().split())
Now = [0]*N
maxL = 1
minR = N
for T in range(0,M):
    L,R = (int(x) for x in input().split())
    if maxL<L:
        maxL = L
    if minR>R:
        minR = R
if maxL>minR:
    print(0)
elif maxL==minR:
    print(1)
elif maxL<minR:
    print(minR-maxL+1) int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x N,M = (int(x) for x in input().split()) N (int(x) for x in input().split()) M Now = [0]*N Now [0]*N [0] 0 N maxL = 1 maxL 1 minR = N minR N for T in range(0,M):
    L,R = (int(x) for x in input().split())
    if maxL<L:
        maxL = L
    if minR>R:
        minR = R T range(0,M) range 0 M int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x L,R = (int(x) for x in input().split()) L (int(x) for x in input().split()) R if maxL<L:
        maxL = L
     maxL<L maxL L maxL = L maxL L if minR>R:
        minR = R minR>R minR R minR = R minR R if maxL>minR:
    print(0)
elif maxL==minR:
    print(1)
elif maxL<minR:
    print(minR-maxL+1) maxL>minR maxL minR print(0) print 0 elif maxL==minR:
    print(1) maxL==minR maxL minR print(1) print 1 elif maxL<minR:
    print(minR-maxL+1) maxL<minR maxL minR print(minR-maxL+1) print minR-maxL+1 minR-maxL minR maxL 1 Now = [0]*N [0]*N Now N,M = (int(x) for x in input().split()) (int(x) for x in input().split()) N minR = R R minR minR = N N minR maxL = 1 1 maxL R = (int(x) for x in input().split()) (int(x) for x in input().split()) R L,R = (int(x) for x in input().split()) (int(x) for x in input().split()) L M = (int(x) for x in input().split()) (int(x) for x in input().split()) M maxL = L L maxL
N,M = (int(x) for x in input().split())
Now = [0]*N
maxL = 1
minR = N
for T in range(0,M):
    L,R = (int(x) for x in input().split())
    if maxL<L:
        maxL = L
    if minR>R:
        minR = R
if maxL>minR:
    print(0)
elif maxL==minR:
    print(1)
elif maxL<minR:
    print(minR-maxL+1)