import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int Lmax = 0;
        int Rmin = N;
        for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt(); 
            Lmax = Math.max(Lmax, L[i]);
            Rmin = Math.min(Rmin, R[i]);
        }
        System.out.println(Lmax <= Rmin ? Rmin - Lmax + 1 : 0);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int Lmax = 0;
        int Rmin = N;
        for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt(); 
            Lmax = Math.max(Lmax, L[i]);
            Rmin = Math.min(Rmin, R[i]);
        }
        System.out.println(Lmax <= Rmin ? Rmin - Lmax + 1 : 0);
    }
} Main public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int Lmax = 0;
        int Rmin = N;
        for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt(); 
            Lmax = Math.max(Lmax, L[i]);
            Rmin = Math.min(Rmin, R[i]);
        }
        System.out.println(Lmax <= Rmin ? Rmin - Lmax + 1 : 0);
    } main {
        
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int Lmax = 0;
        int Rmin = N;
        for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt(); 
            Lmax = Math.max(Lmax, L[i]);
            Rmin = Math.min(Rmin, R[i]);
        }
        System.out.println(Lmax <= Rmin ? Rmin - Lmax + 1 : 0);
    } 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[] L = new int[M]; L new int[M] M int[] R = new int[M]; R new int[M] M int Lmax = 0; Lmax 0 int Rmin = N; Rmin N for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt(); 
            Lmax = Math.max(Lmax, L[i]);
            Rmin = Math.min(Rmin, R[i]);
        } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt(); 
            Lmax = Math.max(Lmax, L[i]);
            Rmin = Math.min(Rmin, R[i]);
        } {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt(); 
            Lmax = Math.max(Lmax, L[i]);
            Rmin = Math.min(Rmin, R[i]);
        } L[i] = sc.nextInt() L[i] L i sc.nextInt() sc.nextInt sc R[i] = sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc Lmax = Math.max(Lmax, L[i]) Lmax Math.max(Lmax, L[i]) Math.max Math Lmax L[i] L i Rmin = Math.min(Rmin, R[i]) Rmin Math.min(Rmin, R[i]) Math.min Math Rmin R[i] R i System.out.println(Lmax <= Rmin ? Rmin - Lmax + 1 : 0) System.out.println System.out System System.out Lmax <= Rmin ? Rmin - Lmax + 1 : 0 Lmax <= Rmin Lmax Rmin Rmin - Lmax + 1 Rmin - Lmax Rmin Lmax 1 0 String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int Lmax = 0;
        int Rmin = N;
        for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt(); 
            Lmax = Math.max(Lmax, L[i]);
            Rmin = Math.min(Rmin, R[i]);
        }
        System.out.println(Lmax <= Rmin ? Rmin - Lmax + 1 : 0);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int Lmax = 0;
        int Rmin = N;
        for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt(); 
            Lmax = Math.max(Lmax, L[i]);
            Rmin = Math.min(Rmin, R[i]);
        }
        System.out.println(Lmax <= Rmin ? Rmin - Lmax + 1 : 0);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int Lmax = 0;
        int Rmin = N;
        for(int i = 0; i < M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt(); 
            Lmax = Math.max(Lmax, L[i]);
            Rmin = Math.min(Rmin, R[i]);
        }
        System.out.println(Lmax <= Rmin ? Rmin - Lmax + 1 : 0);
    }
}