def readinput():
    n,m=map(int,input().split())
    l=[]
    r=[]
    for i in range(m):
        li,ri=map(int,input().split())
        l.append(li)
        r.append(ri)
    return n,m,l,r

def main(n,m,l,r):
    lmax=1
    rmin=n
    for i in range(m):
        lmax=max(lmax,l[i])
        rmin=min(rmin,r[i])
    return max(rmin-lmax+1,0)

if __name__=='__main__':
    n,m,l,r=readinput()
    ans=main(n,m,l,r)
    print(ans) def readinput():
    n,m=map(int,input().split())
    l=[]
    r=[]
    for i in range(m):
        li,ri=map(int,input().split())
        l.append(li)
        r.append(ri)
    return n,m,l,r readinput n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l=[] l [] r=[] r [] for i in range(m):
        li,ri=map(int,input().split())
        l.append(li)
        r.append(ri)
     i range(m) range m li,ri=map(int,input().split()) li map(int,input().split()) map int input().split() ().split () input split ri l.append(li) l.append l append li r.append(ri) r.append r append ri return n,m,l,r return n,m,l,r n m l r def main(n,m,l,r):
    lmax=1
    rmin=n
    for i in range(m):
        lmax=max(lmax,l[i])
        rmin=min(rmin,r[i])
    return max(rmin-lmax+1,0) main lmax=1 lmax 1 rmin=n rmin n for i in range(m):
        lmax=max(lmax,l[i])
        rmin=min(rmin,r[i])
     i range(m) range m lmax=max(lmax,l[i]) lmax max(lmax,l[i]) max lmax l[i] l i rmin=min(rmin,r[i]) rmin min(rmin,r[i]) min rmin r[i] r i return max(rmin-lmax+1,0) max(rmin-lmax+1,0) max rmin-lmax+1 rmin-lmax rmin lmax 1 0 n n m m l l r r if __name__=='__main__':
    n,m,l,r=readinput()
    ans=main(n,m,l,r)
    print(ans) __name__=='__main__' __name__ '__main__' n,m,l,r=readinput() n readinput() readinput m l r ans=main(n,m,l,r) ans main(n,m,l,r) main n m l r print(ans) print ans n,m,l,r=readinput() readinput() n m,l,r=readinput() readinput() m ans=main(n,m,l,r) main(n,m,l,r) ans def readinput():
    n,m=map(int,input().split())
    l=[]
    r=[]
    for i in range(m):
        li,ri=map(int,input().split())
        l.append(li)
        r.append(ri)
    return n,m,l,r def readinput():
    n,m=map(int,input().split())
    l=[]
    r=[]
    for i in range(m):
        li,ri=map(int,input().split())
        l.append(li)
        r.append(ri)
    return n,m,l,r readinput def main(n,m,l,r):
    lmax=1
    rmin=n
    for i in range(m):
        lmax=max(lmax,l[i])
        rmin=min(rmin,r[i])
    return max(rmin-lmax+1,0) def main(n,m,l,r):
    lmax=1
    rmin=n
    for i in range(m):
        lmax=max(lmax,l[i])
        rmin=min(rmin,r[i])
    return max(rmin-lmax+1,0) main l,r=readinput() readinput() l r=readinput() readinput() r
def readinput():
    n,m=map(int,input().split())
    l=[]
    r=[]
    for i in range(m):
        li,ri=map(int,input().split())
        l.append(li)
        r.append(ri)
    return n,m,l,r

def main(n,m,l,r):
    lmax=1
    rmin=n
    for i in range(m):
        lmax=max(lmax,l[i])
        rmin=min(rmin,r[i])
    return max(rmin-lmax+1,0)

if __name__=='__main__':
    n,m,l,r=readinput()
    ans=main(n,m,l,r)
    print(ans)
