import java.util.Scanner;

/**
 * Main
 */
public class Main {

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M+1];
        int[] R = new int[M+1];
        int[] countID = new int[N+1];
        int under = 0;
        int upper = N;

        for(int i=1; i<=M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            under = Math.max(under,L[i]);
            upper = Math.min(upper,R[i]);
        }
        sc.close();

        // for(int i=1; i<=M; i++){
        //     for(int j=L[i]; j <= R[i]; j++){
        //         countID[j]++;
        //     }
        // }

        int ans = upper - under + 1;
        if(ans <= 0){
            System.out.println("0");
        }else{
            System.out.println(ans);
        }
        // for(int i=1; i<=N; i++){
        //     if(countID[i] == M){
        //         ans++;
        //     }
        // }
    }
} 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[] L = new int[M+1];
        int[] R = new int[M+1];
        int[] countID = new int[N+1];
        int under = 0;
        int upper = N;

        for(int i=1; i<=M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            under = Math.max(under,L[i]);
            upper = Math.min(upper,R[i]);
        }
        sc.close();

        // for(int i=1; i<=M; i++){
        //     for(int j=L[i]; j <= R[i]; j++){
        //         countID[j]++;
        //     }
        // }

        int ans = upper - under + 1;
        if(ans <= 0){
            System.out.println("0");
        }else{
            System.out.println(ans);
        }
        // for(int i=1; i<=N; i++){
        //     if(countID[i] == M){
        //         ans++;
        //     }
        // }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M+1];
        int[] R = new int[M+1];
        int[] countID = new int[N+1];
        int under = 0;
        int upper = N;

        for(int i=1; i<=M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            under = Math.max(under,L[i]);
            upper = Math.min(upper,R[i]);
        }
        sc.close();

        // for(int i=1; i<=M; i++){
        //     for(int j=L[i]; j <= R[i]; j++){
        //         countID[j]++;
        //     }
        // }

        int ans = upper - under + 1;
        if(ans <= 0){
            System.out.println("0");
        }else{
            System.out.println(ans);
        }
        // for(int i=1; i<=N; i++){
        //     if(countID[i] == M){
        //         ans++;
        //     }
        // }
    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M+1];
        int[] R = new int[M+1];
        int[] countID = new int[N+1];
        int under = 0;
        int upper = N;

        for(int i=1; i<=M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            under = Math.max(under,L[i]);
            upper = Math.min(upper,R[i]);
        }
        sc.close();

        // for(int i=1; i<=M; i++){
        //     for(int j=L[i]; j <= R[i]; j++){
        //         countID[j]++;
        //     }
        // }

        int ans = upper - under + 1;
        if(ans <= 0){
            System.out.println("0");
        }else{
            System.out.println(ans);
        }
        // for(int i=1; i<=N; i++){
        //     if(countID[i] == M){
        //         ans++;
        //     }
        // }
    } 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+1]; L new int[M+1] M+1 M 1 int[] R = new int[M+1]; R new int[M+1] M+1 M 1 int[] countID = new int[N+1]; countID new int[N+1] N+1 N 1 int under = 0; under 0 int upper = N; upper N for(int i=1; i<=M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            under = Math.max(under,L[i]);
            upper = Math.min(upper,R[i]);
        } int i=1; int i=1; i 1 i<=M i M i++ i++ i {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            under = Math.max(under,L[i]);
            upper = Math.min(upper,R[i]);
        } {
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            under = Math.max(under,L[i]);
            upper = Math.min(upper,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 under = Math.max(under,L[i]) under Math.max(under,L[i]) Math.max Math under L[i] L i upper = Math.min(upper,R[i]) upper Math.min(upper,R[i]) Math.min Math upper R[i] R i sc.close() sc.close sc int ans = upper - under + 1; ans upper - under + 1 upper - under upper under 1 if(ans <= 0){
            System.out.println("0");
        }else{
            System.out.println(ans);
        } ans <= 0 ans 0 {
            System.out.println("0");
        } System.out.println("0") System.out.println System.out System System.out "0" {
            System.out.println(ans);
        } System.out.println(ans) System.out.println System.out System System.out ans 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[] L = new int[M+1];
        int[] R = new int[M+1];
        int[] countID = new int[N+1];
        int under = 0;
        int upper = N;

        for(int i=1; i<=M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            under = Math.max(under,L[i]);
            upper = Math.min(upper,R[i]);
        }
        sc.close();

        // for(int i=1; i<=M; i++){
        //     for(int j=L[i]; j <= R[i]; j++){
        //         countID[j]++;
        //     }
        // }

        int ans = upper - under + 1;
        if(ans <= 0){
            System.out.println("0");
        }else{
            System.out.println(ans);
        }
        // for(int i=1; i<=N; i++){
        //     if(countID[i] == M){
        //         ans++;
        //     }
        // }
    }
} public class Main {

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M+1];
        int[] R = new int[M+1];
        int[] countID = new int[N+1];
        int under = 0;
        int upper = N;

        for(int i=1; i<=M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            under = Math.max(under,L[i]);
            upper = Math.min(upper,R[i]);
        }
        sc.close();

        // for(int i=1; i<=M; i++){
        //     for(int j=L[i]; j <= R[i]; j++){
        //         countID[j]++;
        //     }
        // }

        int ans = upper - under + 1;
        if(ans <= 0){
            System.out.println("0");
        }else{
            System.out.println(ans);
        }
        // for(int i=1; i<=N; i++){
        //     if(countID[i] == M){
        //         ans++;
        //     }
        // }
    }
} Main
import java.util.Scanner;

/**
 * Main
 */
public class Main {

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M+1];
        int[] R = new int[M+1];
        int[] countID = new int[N+1];
        int under = 0;
        int upper = N;

        for(int i=1; i<=M; i++){
            L[i] = sc.nextInt();
            R[i] = sc.nextInt();
            under = Math.max(under,L[i]);
            upper = Math.min(upper,R[i]);
        }
        sc.close();

        // for(int i=1; i<=M; i++){
        //     for(int j=L[i]; j <= R[i]; j++){
        //         countID[j]++;
        //     }
        // }

        int ans = upper - under + 1;
        if(ans <= 0){
            System.out.println("0");
        }else{
            System.out.println(ans);
        }
        // for(int i=1; i<=N; i++){
        //     if(countID[i] == M){
        //         ans++;
        //     }
        // }
    }
}