import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N,M = LI()
left = 0
right = 10000000

for _ in range(M):
    l,r = LI()
    left = max(left,l)
    right = min(right,r)

count = 0
for i in range(1,N+1):
    if left <= i <= right:
        count += 1
print(count) import sys sys def I(): return int(sys.stdin.readline().rstrip()) I def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) LI def S(): return sys.stdin.readline().rstrip() S def LS(): return list(sys.stdin.readline().rstrip().split()) LS N,M = LI() N LI() LI M left = 0 left 0 right = 10000000 right 10000000 for _ in range(M):
    l,r = LI()
    left = max(left,l)
    right = min(right,r) _ range(M) range M l,r = LI() l LI() LI r left = max(left,l) left max(left,l) max left l right = min(right,r) right min(right,r) min right r count = 0 count 0 for i in range(1,N+1):
    if left <= i <= right:
        count += 1 i range(1,N+1) range 1 N+1 N 1 if left <= i <= right:
        count += 1 left <= i <= right left <= i left i right count += 1 count 1 print(count) print count l,r = LI() LI() l N,M = LI() LI() N left = max(left,l) max(left,l) left M = LI() LI() M def S(): return sys.stdin.readline().rstrip() def S(): return sys.stdin.readline().rstrip() S def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I right = 10000000 10000000 right left = 0 0 left right = min(right,r) min(right,r) right count += 1 1 count r = LI() LI() r def LS(): return list(sys.stdin.readline().rstrip().split()) def LS(): return list(sys.stdin.readline().rstrip().split()) LS count = 0 0 count def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) LI
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N,M = LI()
left = 0
right = 10000000

for _ in range(M):
    l,r = LI()
    left = max(left,l)
    right = min(right,r)

count = 0
for i in range(1,N+1):
    if left <= i <= right:
        count += 1
print(count)