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

#ll = [list(map(int,input().split())) for _ in [0]*m]

#l=[]

#r=[]

#for i in range(m):

#  l.append(ll[i][0])

#  r.append(ll[i][1])

#l = max(l)

#r = min(r)



l=0

r=n

for _ in range(m):

  a,b = list(map(int,input().split()))

  l = l if l>a else a

  r = r if r<b else b

print((max([0,r-l+1])))
from sys import stdin

n,m = list(map(int,stdin.readline().split()))

#ll = [list(map(int,input().split())) for _ in [0]*m]

#l=[]

#r=[]

#for i in range(m):

#  l.append(ll[i][0])

#  r.append(ll[i][1])

#l = max(l)

#r = min(r)



l=0

r=n

for _ in range(m):

  a,b = list(map(int,stdin.readline().split()))

  l = l if l>a else a

  r = r if r<b else b

print((max([0,r-l+1])))
n, m = list(map(int, input().split()))
# ll = [list(map(int,input().split())) for _ in [0]*m]
# l=[]
# r=[]
# for i in range(m):
#  l.append(ll[i][0])
#  r.append(ll[i][1])
# l = max(l)
# r = min(r)
l = 0
r = n
for _ in range(m):
    a, b = list(map(int, input().split()))
    l = l if l > a else a
    r = r if r < b else b
print((max([0, r - l + 1])))

from sys import stdin

n, m = list(map(int, stdin.readline().split()))
# ll = [list(map(int,input().split())) for _ in [0]*m]
# l=[]
# r=[]
# for i in range(m):
#  l.append(ll[i][0])
#  r.append(ll[i][1])
# l = max(l)
# r = min(r)
l = 0
r = n
for _ in range(m):
    a, b = list(map(int, stdin.readline().split()))
    l = l if l > a else a
    r = r if r < b else b
print((max([0, r - l + 1])))

-n, m = list(map(int, input().split())) +from sys import stdin + +n, m = list(map(int, stdin.readline().split())) -    a, b = list(map(int, input().split())) +    a, b = list(map(int, stdin.readline().split()))