import 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[] Lz = new int[M];
        int[] Rz = new int[M];
        for (int m = 0; m < M; m++){
            Lz[m] = sc.nextInt();
            Rz[m] = sc.nextInt();
        }
        int left = 0;
        int right = N;
        for (int m = 0; m < M; m++){
            if (Lz[m] > left) left = Lz[m];
            if (Rz[m] < right) right = Rz[m];
            if (left > right) {
                System.out.println("0");
//                break;
                System.exit(0);
            }
        }
        System.out.println(right-left+1);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] Lz = new int[M];
        int[] Rz = new int[M];
        for (int m = 0; m < M; m++){
            Lz[m] = sc.nextInt();
            Rz[m] = sc.nextInt();
        }
        int left = 0;
        int right = N;
        for (int m = 0; m < M; m++){
            if (Lz[m] > left) left = Lz[m];
            if (Rz[m] < right) right = Rz[m];
            if (left > right) {
                System.out.println("0");
//                break;
                System.exit(0);
            }
        }
        System.out.println(right-left+1);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] Lz = new int[M];
        int[] Rz = new int[M];
        for (int m = 0; m < M; m++){
            Lz[m] = sc.nextInt();
            Rz[m] = sc.nextInt();
        }
        int left = 0;
        int right = N;
        for (int m = 0; m < M; m++){
            if (Lz[m] > left) left = Lz[m];
            if (Rz[m] < right) right = Rz[m];
            if (left > right) {
                System.out.println("0");
//                break;
                System.exit(0);
            }
        }
        System.out.println(right-left+1);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] Lz = new int[M];
        int[] Rz = new int[M];
        for (int m = 0; m < M; m++){
            Lz[m] = sc.nextInt();
            Rz[m] = sc.nextInt();
        }
        int left = 0;
        int right = N;
        for (int m = 0; m < M; m++){
            if (Lz[m] > left) left = Lz[m];
            if (Rz[m] < right) right = Rz[m];
            if (left > right) {
                System.out.println("0");
//                break;
                System.exit(0);
            }
        }
        System.out.println(right-left+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[] Lz = new int[M]; Lz new int[M] M int[] Rz = new int[M]; Rz new int[M] M for (int m = 0; m < M; m++){
            Lz[m] = sc.nextInt();
            Rz[m] = sc.nextInt();
        } int m = 0; int m = 0; m 0 m < M m M m++ m++ m {
            Lz[m] = sc.nextInt();
            Rz[m] = sc.nextInt();
        } {
            Lz[m] = sc.nextInt();
            Rz[m] = sc.nextInt();
        } Lz[m] = sc.nextInt() Lz[m] Lz m sc.nextInt() sc.nextInt sc Rz[m] = sc.nextInt() Rz[m] Rz m sc.nextInt() sc.nextInt sc int left = 0; left 0 int right = N; right N for (int m = 0; m < M; m++){
            if (Lz[m] > left) left = Lz[m];
            if (Rz[m] < right) right = Rz[m];
            if (left > right) {
                System.out.println("0");
//                break;
                System.exit(0);
            }
        } int m = 0; int m = 0; m 0 m < M m M m++ m++ m {
            if (Lz[m] > left) left = Lz[m];
            if (Rz[m] < right) right = Rz[m];
            if (left > right) {
                System.out.println("0");
//                break;
                System.exit(0);
            }
        } {
            if (Lz[m] > left) left = Lz[m];
            if (Rz[m] < right) right = Rz[m];
            if (left > right) {
                System.out.println("0");
//                break;
                System.exit(0);
            }
        } if (Lz[m] > left) left = Lz[m]; Lz[m] > left Lz[m] Lz m left left = Lz[m] left Lz[m] Lz m if (Rz[m] < right) right = Rz[m]; Rz[m] < right Rz[m] Rz m right right = Rz[m] right Rz[m] Rz m if (left > right) {
                System.out.println("0");
//                break;
                System.exit(0);
            } left > right left right {
                System.out.println("0");
//                break;
                System.exit(0);
            } System.out.println("0") System.out.println System.out System System.out "0" System.exit(0) System.exit System 0 System.out.println(right-left+1) System.out.println System.out System System.out right-left+1 right-left right left 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[] Lz = new int[M];
        int[] Rz = new int[M];
        for (int m = 0; m < M; m++){
            Lz[m] = sc.nextInt();
            Rz[m] = sc.nextInt();
        }
        int left = 0;
        int right = N;
        for (int m = 0; m < M; m++){
            if (Lz[m] > left) left = Lz[m];
            if (Rz[m] < right) right = Rz[m];
            if (left > right) {
                System.out.println("0");
//                break;
                System.exit(0);
            }
        }
        System.out.println(right-left+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[] Lz = new int[M];
        int[] Rz = new int[M];
        for (int m = 0; m < M; m++){
            Lz[m] = sc.nextInt();
            Rz[m] = sc.nextInt();
        }
        int left = 0;
        int right = N;
        for (int m = 0; m < M; m++){
            if (Lz[m] > left) left = Lz[m];
            if (Rz[m] < right) right = Rz[m];
            if (left > right) {
                System.out.println("0");
//                break;
                System.exit(0);
            }
        }
        System.out.println(right-left+1);
    }
} Main
import 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[] Lz = new int[M];
        int[] Rz = new int[M];
        for (int m = 0; m < M; m++){
            Lz[m] = sc.nextInt();
            Rz[m] = sc.nextInt();
        }
        int left = 0;
        int right = N;
        for (int m = 0; m < M; m++){
            if (Lz[m] > left) left = Lz[m];
            if (Rz[m] < right) right = Rz[m];
            if (left > right) {
                System.out.println("0");
//                break;
                System.exit(0);
            }
        }
        System.out.println(right-left+1);
    }
}