import java.util.Scanner;

public class Main{
    
    public static void main (String[] args){
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int min = 2147483647;
        int max = 0;
        for (int index=0; index<M; index++){
            
            int left = sc.nextInt();
            int right = sc.nextInt();
            if (left>max){
                max=left;
            }
            if (right<min){
                min=right;
            }
        }
        
        if (min<max){
            System.out.println("0");
        } else {
            System.out.println(min-max+1);
        }
        
        
    }
} import java.util.Scanner; Scanner java.util public class Main{
    
    public static void main (String[] args){
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int min = 2147483647;
        int max = 0;
        for (int index=0; index<M; index++){
            
            int left = sc.nextInt();
            int right = sc.nextInt();
            if (left>max){
                max=left;
            }
            if (right<min){
                min=right;
            }
        }
        
        if (min<max){
            System.out.println("0");
        } else {
            System.out.println(min-max+1);
        }
        
        
    }
} Main public static void main (String[] args){
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int min = 2147483647;
        int max = 0;
        for (int index=0; index<M; index++){
            
            int left = sc.nextInt();
            int right = sc.nextInt();
            if (left>max){
                max=left;
            }
            if (right<min){
                min=right;
            }
        }
        
        if (min<max){
            System.out.println("0");
        } else {
            System.out.println(min-max+1);
        }
        
        
    } main {
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int min = 2147483647;
        int max = 0;
        for (int index=0; index<M; index++){
            
            int left = sc.nextInt();
            int right = sc.nextInt();
            if (left>max){
                max=left;
            }
            if (right<min){
                min=right;
            }
        }
        
        if (min<max){
            System.out.println("0");
        } else {
            System.out.println(min-max+1);
        }
        
        
    } 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 min = 2147483647; min 2147483647 int max = 0; max 0 for (int index=0; index<M; index++){
            
            int left = sc.nextInt();
            int right = sc.nextInt();
            if (left>max){
                max=left;
            }
            if (right<min){
                min=right;
            }
        } int index=0; int index=0; index 0 index<M index M index++ index++ index {
            
            int left = sc.nextInt();
            int right = sc.nextInt();
            if (left>max){
                max=left;
            }
            if (right<min){
                min=right;
            }
        } {
            
            int left = sc.nextInt();
            int right = sc.nextInt();
            if (left>max){
                max=left;
            }
            if (right<min){
                min=right;
            }
        } int left = sc.nextInt(); left sc.nextInt() sc.nextInt sc int right = sc.nextInt(); right sc.nextInt() sc.nextInt sc if (left>max){
                max=left;
            } left>max left max {
                max=left;
            } max=left max left if (right<min){
                min=right;
            } right<min right min {
                min=right;
            } min=right min right if (min<max){
            System.out.println("0");
        } else {
            System.out.println(min-max+1);
        } min<max min max {
            System.out.println("0");
        } System.out.println("0") System.out.println System.out System System.out "0" {
            System.out.println(min-max+1);
        } System.out.println(min-max+1) System.out.println System.out System System.out min-max+1 min-max min max 1 String[] args args public class Main{
    
    public static void main (String[] args){
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int min = 2147483647;
        int max = 0;
        for (int index=0; index<M; index++){
            
            int left = sc.nextInt();
            int right = sc.nextInt();
            if (left>max){
                max=left;
            }
            if (right<min){
                min=right;
            }
        }
        
        if (min<max){
            System.out.println("0");
        } else {
            System.out.println(min-max+1);
        }
        
        
    }
} public class Main{
    
    public static void main (String[] args){
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int min = 2147483647;
        int max = 0;
        for (int index=0; index<M; index++){
            
            int left = sc.nextInt();
            int right = sc.nextInt();
            if (left>max){
                max=left;
            }
            if (right<min){
                min=right;
            }
        }
        
        if (min<max){
            System.out.println("0");
        } else {
            System.out.println(min-max+1);
        }
        
        
    }
} Main
import java.util.Scanner;

public class Main{
    
    public static void main (String[] args){
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int min = 2147483647;
        int max = 0;
        for (int index=0; index<M; index++){
            
            int left = sc.nextInt();
            int right = sc.nextInt();
            if (left>max){
                max=left;
            }
            if (right<min){
                min=right;
            }
        }
        
        if (min<max){
            System.out.println("0");
        } else {
            System.out.println(min-max+1);
        }
        
        
    }
}