import math
s = input().split()
n=int(s[0])
m=int(s[1])
l=0
r=float('inf')
for i in range(m):
    s = list(map(int,input().split()))
    l=max(l,s[0])
    r=min(r,s[1])
a=r-l
if a>=0:
    print(a+1)
else:
    print(0) import math math s = input().split() s input().split() ().split () input split n=int(s[0]) n int(s[0]) int s[0] s 0 m=int(s[1]) m int(s[1]) int s[1] s 1 l=0 l 0 r=float('inf') r float('inf') float 'inf' for i in range(m):
    s = list(map(int,input().split()))
    l=max(l,s[0])
    r=min(r,s[1]) i range(m) range m s = list(map(int,input().split())) s list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split l=max(l,s[0]) l max(l,s[0]) max l s[0] s 0 r=min(r,s[1]) r min(r,s[1]) min r s[1] s 1 a=r-l a r-l r l if a>=0:
    print(a+1)
else:
    print(0) a>=0 a 0 print(a+1) print a+1 a 1 print(0) print 0 n=int(s[0]) int(s[0]) n r=min(r,s[1]) min(r,s[1]) r l=max(l,s[0]) max(l,s[0]) l l=0 0 l m=int(s[1]) int(s[1]) m s = list(map(int,input().split())) list(map(int,input().split())) s a=r-l r-l a s = input().split() input().split() s r=float('inf') float('inf') r
import math
s = input().split()
n=int(s[0])
m=int(s[1])
l=0
r=float('inf')
for i in range(m):
    s = list(map(int,input().split()))
    l=max(l,s[0])
    r=min(r,s[1])
a=r-l
if a>=0:
    print(a+1)
else:
    print(0)
