#import math
#import itertools
import numpy as np
#from collections import deque

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n,m=INTM()
    ls=[]
    rs=[]
    for i in range(m):
        l,r=INTM()
        ls.append(l)
        rs.append(r)
    
    ans=min(rs)-max(ls)+1
    if ans<=0:
        ans=0
    print(ans)



    
if __name__=='__main__':
    do() import numpy as np numpy INT = lambda: int(input()) INT lambda: int(input()) int(input()) int input() input INTM = lambda: map(int,input().split()) INTM lambda: map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split STRM = lambda: map(str,input().split()) STRM lambda: map(str,input().split()) map(str,input().split()) map str input().split() ().split () input split STR = lambda: str(input()) STR lambda: str(input()) str(input()) str input() input LIST = lambda: list(map(int,input().split())) LIST lambda: list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split LISTS = lambda: list(map(str,input().split())) LISTS lambda: list(map(str,input().split())) list(map(str,input().split())) list map(str,input().split()) map str input().split() ().split () input split def do():
    n,m=INTM()
    ls=[]
    rs=[]
    for i in range(m):
        l,r=INTM()
        ls.append(l)
        rs.append(r)
    
    ans=min(rs)-max(ls)+1
    if ans<=0:
        ans=0
    print(ans)



     do n,m=INTM() n INTM() INTM m ls=[] ls [] rs=[] rs [] for i in range(m):
        l,r=INTM()
        ls.append(l)
        rs.append(r)
    
     i range(m) range m l,r=INTM() l INTM() INTM r ls.append(l) ls.append ls append l rs.append(r) rs.append rs append r ans=min(rs)-max(ls)+1 ans min(rs)-max(ls)+1 min(rs)-max(ls) min(rs) min rs max(ls) max ls 1 if ans<=0:
        ans=0
     ans<=0 ans 0 ans=0 ans 0 print(ans) print ans if __name__=='__main__':
    do() __name__=='__main__' __name__ '__main__' do() do LISTS = lambda: list(map(str,input().split())) lambda: list(map(str,input().split())) LISTS STRM = lambda: map(str,input().split()) lambda: map(str,input().split()) STRM INT = lambda: int(input()) lambda: int(input()) INT LIST = lambda: list(map(int,input().split())) lambda: list(map(int,input().split())) LIST def do():
    n,m=INTM()
    ls=[]
    rs=[]
    for i in range(m):
        l,r=INTM()
        ls.append(l)
        rs.append(r)
    
    ans=min(rs)-max(ls)+1
    if ans<=0:
        ans=0
    print(ans)



     def do():
    n,m=INTM()
    ls=[]
    rs=[]
    for i in range(m):
        l,r=INTM()
        ls.append(l)
        rs.append(r)
    
    ans=min(rs)-max(ls)+1
    if ans<=0:
        ans=0
    print(ans)



     do INTM = lambda: map(int,input().split()) lambda: map(int,input().split()) INTM STR = lambda: str(input()) lambda: str(input()) STR
#import math
#import itertools
import numpy as np
#from collections import deque

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n,m=INTM()
    ls=[]
    rs=[]
    for i in range(m):
        l,r=INTM()
        ls.append(l)
        rs.append(r)
    
    ans=min(rs)-max(ls)+1
    if ans<=0:
        ans=0
    print(ans)



    
if __name__=='__main__':
    do()