import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,M=mi()

    L,R=-INF,INF
    for i in range(M):
        l,r = mi()
        if L < l:
            L = l
        if r < R:
            R = r
        
        if R < L:
            print(0)
            exit()
    
    print(R-L+1)



        





if __name__ == "__main__":
    main() import sys sys sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 def mi(): return map(int,input().split()) mi def ii(): return int(input()) ii def isp(): return input().split() isp def deb(text): print("-------\n{}\n-------".format(text)) deb text text INF=10**20 INF 10**20 10 20 def main():
    N,M=mi()

    L,R=-INF,INF
    for i in range(M):
        l,r = mi()
        if L < l:
            L = l
        if r < R:
            R = r
        
        if R < L:
            print(0)
            exit()
    
    print(R-L+1)



         main N,M=mi() N mi() mi M L,R=-INF,INF L -INF INF R INF for i in range(M):
        l,r = mi()
        if L < l:
            L = l
        if r < R:
            R = r
        
        if R < L:
            print(0)
            exit()
    
     i range(M) range M l,r = mi() l mi() mi r if L < l:
            L = l
         L < l L l L = l L l if r < R:
            R = r
        
         r < R r R R = r R r if R < L:
            print(0)
            exit()
    
     R < L R L print(0) print 0 exit() exit print(R-L+1) print R-L+1 R-L R L 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N,M=mi()

    L,R=-INF,INF
    for i in range(M):
        l,r = mi()
        if L < l:
            L = l
        if r < R:
            R = r
        
        if R < L:
            print(0)
            exit()
    
    print(R-L+1)



         def main():
    N,M=mi()

    L,R=-INF,INF
    for i in range(M):
        l,r = mi()
        if L < l:
            L = l
        if r < R:
            R = r
        
        if R < L:
            print(0)
            exit()
    
    print(R-L+1)



         main def deb(text): print("-------\n{}\n-------".format(text)) def deb(text): print("-------\n{}\n-------".format(text)) deb def isp(): return input().split() def isp(): return input().split() isp INF=10**20 10**20 INF def ii(): return int(input()) def ii(): return int(input()) ii def mi(): return map(int,input().split()) def mi(): return map(int,input().split()) mi
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N,M=mi()

    L,R=-INF,INF
    for i in range(M):
        l,r = mi()
        if L < l:
            L = l
        if r < R:
            R = r
        
        if R < L:
            print(0)
            exit()
    
    print(R-L+1)



        





if __name__ == "__main__":
    main()