import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    L=[0]*(N+1)
    for _ in range(M):
        l,r=MI()
        l-=1
        r-=1
        L[l]+=1
        L[r+1]-=1
        
    for i in range(N):
        L[i+1]+=L[i]
        
    ans=0
    
    for i in range(N):
        if L[i]>=M:
            ans+=1
            
    print(ans)
    

main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def I(): return int(input()) I def MI(): return map(int, input().split()) MI def LI(): return list(map(int, input().split())) LI def main():
    mod=10**9+7
    N,M=MI()
    L=[0]*(N+1)
    for _ in range(M):
        l,r=MI()
        l-=1
        r-=1
        L[l]+=1
        L[r+1]-=1
        
    for i in range(N):
        L[i+1]+=L[i]
        
    ans=0
    
    for i in range(N):
        if L[i]>=M:
            ans+=1
            
    print(ans)
     main mod=10**9+7 mod 10**9+7 10**9 10 9 7 N,M=MI() N MI() MI M L=[0]*(N+1) L [0]*(N+1) [0] 0 N+1 N 1 for _ in range(M):
        l,r=MI()
        l-=1
        r-=1
        L[l]+=1
        L[r+1]-=1
        
     _ range(M) range M l,r=MI() l MI() MI r l-=1 l 1 r-=1 r 1 L[l]+=1 L[l] L l 1 L[r+1]-=1 L[r+1] L r+1 r 1 1 for i in range(N):
        L[i+1]+=L[i]
        
     i range(N) range N L[i+1]+=L[i] L[i+1] L i+1 i 1 L[i] L i ans=0 ans 0 for i in range(N):
        if L[i]>=M:
            ans+=1
            
     i range(N) range N if L[i]>=M:
            ans+=1
            
     L[i]>=M L[i] L i M ans+=1 ans 1 print(ans) print ans main() main def I(): return int(input()) def I(): return int(input()) I def MI(): return map(int, input().split()) def MI(): return map(int, input().split()) MI def main():
    mod=10**9+7
    N,M=MI()
    L=[0]*(N+1)
    for _ in range(M):
        l,r=MI()
        l-=1
        r-=1
        L[l]+=1
        L[r+1]-=1
        
    for i in range(N):
        L[i+1]+=L[i]
        
    ans=0
    
    for i in range(N):
        if L[i]>=M:
            ans+=1
            
    print(ans)
     def main():
    mod=10**9+7
    N,M=MI()
    L=[0]*(N+1)
    for _ in range(M):
        l,r=MI()
        l-=1
        r-=1
        L[l]+=1
        L[r+1]-=1
        
    for i in range(N):
        L[i+1]+=L[i]
        
    ans=0
    
    for i in range(N):
        if L[i]>=M:
            ans+=1
            
    print(ans)
     main def LI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) LI input = sys.stdin.readline sys.stdin.readline input
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    L=[0]*(N+1)
    for _ in range(M):
        l,r=MI()
        l-=1
        r-=1
        L[l]+=1
        L[r+1]-=1
        
    for i in range(N):
        L[i+1]+=L[i]
        
    ans=0
    
    for i in range(N):
        if L[i]>=M:
            ans+=1
            
    print(ans)
    

main()
