import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();// cards
        int M = scan.nextInt();// gates
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scan.nextInt();
            R[i] = scan.nextInt();
        }//O(M)
        Arrays.sort(L);
        Arrays.sort(R);
        if(L[M-1] <= R[0]){
            System.out.print(R[0] - L[M-1] + 1);
        }
        else{
            System.out.print(0);
        }

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();// cards
        int M = scan.nextInt();// gates
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scan.nextInt();
            R[i] = scan.nextInt();
        }//O(M)
        Arrays.sort(L);
        Arrays.sort(R);
        if(L[M-1] <= R[0]){
            System.out.print(R[0] - L[M-1] + 1);
        }
        else{
            System.out.print(0);
        }

    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();// cards
        int M = scan.nextInt();// gates
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scan.nextInt();
            R[i] = scan.nextInt();
        }//O(M)
        Arrays.sort(L);
        Arrays.sort(R);
        if(L[M-1] <= R[0]){
            System.out.print(R[0] - L[M-1] + 1);
        }
        else{
            System.out.print(0);
        }

    } main {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();// cards
        int M = scan.nextInt();// gates
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scan.nextInt();
            R[i] = scan.nextInt();
        }//O(M)
        Arrays.sort(L);
        Arrays.sort(R);
        if(L[M-1] <= R[0]){
            System.out.print(R[0] - L[M-1] + 1);
        }
        else{
            System.out.print(0);
        }

    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int M = scan.nextInt(); M scan.nextInt() scan.nextInt scan int[] L = new int[M]; L new int[M] M int[] R = new int[M]; R new int[M] M for (int i = 0; i < M; i++) {
            L[i] = scan.nextInt();
            R[i] = scan.nextInt();
        }//O(M) int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
            L[i] = scan.nextInt();
            R[i] = scan.nextInt();
        }//O(M) {
            L[i] = scan.nextInt();
            R[i] = scan.nextInt();
        } L[i] = scan.nextInt() L[i] L i scan.nextInt() scan.nextInt scan R[i] = scan.nextInt() R[i] R i scan.nextInt() scan.nextInt scan Arrays.sort(L) Arrays.sort Arrays L Arrays.sort(R) Arrays.sort Arrays R if(L[M-1] <= R[0]){
            System.out.print(R[0] - L[M-1] + 1);
        }
        else{
            System.out.print(0);
        } L[M-1] <= R[0] L[M-1] L M-1 M 1 R[0] R 0 {
            System.out.print(R[0] - L[M-1] + 1);
        } System.out.print(R[0] - L[M-1] + 1) System.out.print System.out System System.out R[0] - L[M-1] + 1 R[0] - L[M-1] R[0] R 0 L[M-1] L M-1 M 1 1 {
            System.out.print(0);
        } System.out.print(0) System.out.print System.out System System.out 0 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();// cards
        int M = scan.nextInt();// gates
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scan.nextInt();
            R[i] = scan.nextInt();
        }//O(M)
        Arrays.sort(L);
        Arrays.sort(R);
        if(L[M-1] <= R[0]){
            System.out.print(R[0] - L[M-1] + 1);
        }
        else{
            System.out.print(0);
        }

    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();// cards
        int M = scan.nextInt();// gates
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scan.nextInt();
            R[i] = scan.nextInt();
        }//O(M)
        Arrays.sort(L);
        Arrays.sort(R);
        if(L[M-1] <= R[0]){
            System.out.print(R[0] - L[M-1] + 1);
        }
        else{
            System.out.print(0);
        }

    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();// cards
        int M = scan.nextInt();// gates
        int[] L = new int[M];
        int[] R = new int[M];
        for (int i = 0; i < M; i++) {
            L[i] = scan.nextInt();
            R[i] = scan.nextInt();
        }//O(M)
        Arrays.sort(L);
        Arrays.sort(R);
        if(L[M-1] <= R[0]){
            System.out.print(R[0] - L[M-1] + 1);
        }
        else{
            System.out.print(0);
        }

    }
}