def resolve():
    n,m=map(int,input().split())
    l=0
    r=n
    for i in range(m):
        nl,nr=map(int,input().split())
        l=max(l,nl)
        r=min(r,nr)
    print(max(r-l+1,0))
resolve() def resolve():
    n,m=map(int,input().split())
    l=0
    r=n
    for i in range(m):
        nl,nr=map(int,input().split())
        l=max(l,nl)
        r=min(r,nr)
    print(max(r-l+1,0)) resolve n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l=0 l 0 r=n r n for i in range(m):
        nl,nr=map(int,input().split())
        l=max(l,nl)
        r=min(r,nr)
     i range(m) range m nl,nr=map(int,input().split()) nl map(int,input().split()) map int input().split() ().split () input split nr l=max(l,nl) l max(l,nl) max l nl r=min(r,nr) r min(r,nr) min r nr print(max(r-l+1,0)) print max(r-l+1,0) max r-l+1 r-l r l 1 0 resolve() resolve def resolve():
    n,m=map(int,input().split())
    l=0
    r=n
    for i in range(m):
        nl,nr=map(int,input().split())
        l=max(l,nl)
        r=min(r,nr)
    print(max(r-l+1,0)) def resolve():
    n,m=map(int,input().split())
    l=0
    r=n
    for i in range(m):
        nl,nr=map(int,input().split())
        l=max(l,nl)
        r=min(r,nr)
    print(max(r-l+1,0)) resolve
def resolve():
    n,m=map(int,input().split())
    l=0
    r=n
    for i in range(m):
        nl,nr=map(int,input().split())
        l=max(l,nl)
        r=min(r,nr)
    print(max(r-l+1,0))
resolve()