import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lmax=0;
        int rmin=n;
        for(int i=0;i<m;i++){
           int ninja = sc.nextInt();
           int unk0 = sc.nextInt();
           if(ninja>lmax){
               lmax=ninja;
           }
           if(unk0<rmin){
               rmin=unk0;
           }
        }
        int sum=rmin-lmax+1;
        if(sum<0){
            sum=0;
        }
        System.out.println(sum);
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lmax=0;
        int rmin=n;
        for(int i=0;i<m;i++){
           int ninja = sc.nextInt();
           int unk0 = sc.nextInt();
           if(ninja>lmax){
               lmax=ninja;
           }
           if(unk0<rmin){
               rmin=unk0;
           }
        }
        int sum=rmin-lmax+1;
        if(sum<0){
            sum=0;
        }
        System.out.println(sum);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lmax=0;
        int rmin=n;
        for(int i=0;i<m;i++){
           int ninja = sc.nextInt();
           int unk0 = sc.nextInt();
           if(ninja>lmax){
               lmax=ninja;
           }
           if(unk0<rmin){
               rmin=unk0;
           }
        }
        int sum=rmin-lmax+1;
        if(sum<0){
            sum=0;
        }
        System.out.println(sum);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lmax=0;
        int rmin=n;
        for(int i=0;i<m;i++){
           int ninja = sc.nextInt();
           int unk0 = sc.nextInt();
           if(ninja>lmax){
               lmax=ninja;
           }
           if(unk0<rmin){
               rmin=unk0;
           }
        }
        int sum=rmin-lmax+1;
        if(sum<0){
            sum=0;
        }
        System.out.println(sum);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int lmax=0; lmax 0 int rmin=n; rmin n for(int i=0;i<m;i++){
           int ninja = sc.nextInt();
           int unk0 = sc.nextInt();
           if(ninja>lmax){
               lmax=ninja;
           }
           if(unk0<rmin){
               rmin=unk0;
           }
        } int i=0; int i=0; i 0 i<m i m i++ i++ i {
           int ninja = sc.nextInt();
           int unk0 = sc.nextInt();
           if(ninja>lmax){
               lmax=ninja;
           }
           if(unk0<rmin){
               rmin=unk0;
           }
        } {
           int ninja = sc.nextInt();
           int unk0 = sc.nextInt();
           if(ninja>lmax){
               lmax=ninja;
           }
           if(unk0<rmin){
               rmin=unk0;
           }
        } int ninja = sc.nextInt(); ninja sc.nextInt() sc.nextInt sc int unk0 = sc.nextInt(); unk0 sc.nextInt() sc.nextInt sc if(ninja>lmax){
               lmax=ninja;
           } ninja>lmax ninja lmax {
               lmax=ninja;
           } lmax=ninja lmax ninja if(unk0<rmin){
               rmin=unk0;
           } unk0<rmin unk0 rmin {
               rmin=unk0;
           } rmin=unk0 rmin unk0 int sum=rmin-lmax+1; sum rmin-lmax+1 rmin-lmax rmin lmax 1 if(sum<0){
            sum=0;
        } sum<0 sum 0 {
            sum=0;
        } sum=0 sum 0 System.out.println(sum) System.out.println System.out System System.out sum String[] args args
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int lmax=0;
        int rmin=n;
        for(int i=0;i<m;i++){
           int ninja = sc.nextInt();
           int unk0 = sc.nextInt();
           if(ninja>lmax){
               lmax=ninja;
           }
           if(unk0<rmin){
               rmin=unk0;
           }
        }
        int sum=rmin-lmax+1;
        if(sum<0){
            sum=0;
        }
        System.out.println(sum);
    }
}