import math
import collections
import itertools

def YesNo(Bool):
    if(Bool):
        print("Yes")
    else:
        print("No")
    return

def resolve():

    N,M=map(int,input().split())
    L=[0]*M
    R=[0]*M
    Lmax=0
    Rmin=10**10
    for i in range(M):
        L[i],R[i]=map(int,input().split())
        Rmin=min(R[i],Rmin)
        Lmax=max(L[i],Lmax)

    print(max(0,Rmin-Lmax+1))

resolve() import math math import collections collections import itertools itertools def YesNo(Bool):
    if(Bool):
        print("Yes")
    else:
        print("No")
    return YesNo if(Bool):
        print("Yes")
    else:
        print("No")
     Bool print("Yes") print "Yes" print("No") print "No" return Bool Bool def resolve():

    N,M=map(int,input().split())
    L=[0]*M
    R=[0]*M
    Lmax=0
    Rmin=10**10
    for i in range(M):
        L[i],R[i]=map(int,input().split())
        Rmin=min(R[i],Rmin)
        Lmax=max(L[i],Lmax)

    print(max(0,Rmin-Lmax+1)) resolve N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M L=[0]*M L [0]*M [0] 0 M R=[0]*M R [0]*M [0] 0 M Lmax=0 Lmax 0 Rmin=10**10 Rmin 10**10 10 10 for i in range(M):
        L[i],R[i]=map(int,input().split())
        Rmin=min(R[i],Rmin)
        Lmax=max(L[i],Lmax)

     i range(M) range M L[i],R[i]=map(int,input().split()) L[i] L i map(int,input().split()) map int input().split() ().split () input split R[i] R i Rmin=min(R[i],Rmin) Rmin min(R[i],Rmin) min R[i] R i Rmin Lmax=max(L[i],Lmax) Lmax max(L[i],Lmax) max L[i] L i Lmax print(max(0,Rmin-Lmax+1)) print max(0,Rmin-Lmax+1) max 0 Rmin-Lmax+1 Rmin-Lmax Rmin Lmax 1 resolve() resolve def resolve():

    N,M=map(int,input().split())
    L=[0]*M
    R=[0]*M
    Lmax=0
    Rmin=10**10
    for i in range(M):
        L[i],R[i]=map(int,input().split())
        Rmin=min(R[i],Rmin)
        Lmax=max(L[i],Lmax)

    print(max(0,Rmin-Lmax+1)) def resolve():

    N,M=map(int,input().split())
    L=[0]*M
    R=[0]*M
    Lmax=0
    Rmin=10**10
    for i in range(M):
        L[i],R[i]=map(int,input().split())
        Rmin=min(R[i],Rmin)
        Lmax=max(L[i],Lmax)

    print(max(0,Rmin-Lmax+1)) resolve def YesNo(Bool):
    if(Bool):
        print("Yes")
    else:
        print("No")
    return def YesNo(Bool):
    if(Bool):
        print("Yes")
    else:
        print("No")
    return YesNo
import math
import collections
import itertools

def YesNo(Bool):
    if(Bool):
        print("Yes")
    else:
        print("No")
    return

def resolve():

    N,M=map(int,input().split())
    L=[0]*M
    R=[0]*M
    Lmax=0
    Rmin=10**10
    for i in range(M):
        L[i],R[i]=map(int,input().split())
        Rmin=min(R[i],Rmin)
        Lmax=max(L[i],Lmax)

    print(max(0,Rmin-Lmax+1))

resolve()
