n,m=map(int,input().split())
count=0
s=[0]*(n+1)
L=0
R=10**5
 
for i in range(m):
  l,r=map(int,input().split())
  L=max(l,L)
  R=min(r,R)
  
if (R-L+1)>=0:
  print(R-L+1)
else:
  print(0) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m count=0 count 0 s=[0]*(n+1) s [0]*(n+1) [0] 0 n+1 n 1 L=0 L 0 R=10**5 R 10**5 10 5 for i in range(m):
  l,r=map(int,input().split())
  L=max(l,L)
  R=min(r,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 L=max(l,L) L max(l,L) max l L R=min(r,R) R min(r,R) min r R if (R-L+1)>=0:
  print(R-L+1)
else:
  print(0) (R-L+1)>=0 R-L+1 R-L R L 1 0 print(R-L+1) print R-L+1 R-L R L 1 print(0) print 0 count=0 0 count L=max(l,L) max(l,L) L L=0 0 L s=[0]*(n+1) [0]*(n+1) s m=map(int,input().split()) map(int,input().split()) m R=min(r,R) min(r,R) R l,r=map(int,input().split()) map(int,input().split()) l r=map(int,input().split()) map(int,input().split()) r n,m=map(int,input().split()) map(int,input().split()) n R=10**5 10**5 R
n,m=map(int,input().split())
count=0
s=[0]*(n+1)
L=0
R=10**5
 
for i in range(m):
  l,r=map(int,input().split())
  L=max(l,L)
  R=min(r,R)
  
if (R-L+1)>=0:
  print(R-L+1)
else:
  print(0)