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[] L = new int[M];
        int[] R = new int[M];
        int cnt = 0;
        int Lmax = 0;
        int Rmin = 100000;
        for (int i=0; i<M; i++) {
            L[i] = sc.nextInt();
            if (L[i] > Lmax) Lmax = L[i];
            R[i] = sc.nextInt();
            if (R[i] < Rmin) Rmin = R[i];
        }
        for (int i=Lmax; i<=Rmin; i++) {
            cnt++;
        }
        System.out.println(cnt);
    }
} 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[] L = new int[M];
        int[] R = new int[M];
        int cnt = 0;
        int Lmax = 0;
        int Rmin = 100000;
        for (int i=0; i<M; i++) {
            L[i] = sc.nextInt();
            if (L[i] > Lmax) Lmax = L[i];
            R[i] = sc.nextInt();
            if (R[i] < Rmin) Rmin = R[i];
        }
        for (int i=Lmax; i<=Rmin; i++) {
            cnt++;
        }
        System.out.println(cnt);
    }
} 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];
        int[] R = new int[M];
        int cnt = 0;
        int Lmax = 0;
        int Rmin = 100000;
        for (int i=0; i<M; i++) {
            L[i] = sc.nextInt();
            if (L[i] > Lmax) Lmax = L[i];
            R[i] = sc.nextInt();
            if (R[i] < Rmin) Rmin = R[i];
        }
        for (int i=Lmax; i<=Rmin; i++) {
            cnt++;
        }
        System.out.println(cnt);
    } 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 cnt = 0;
        int Lmax = 0;
        int Rmin = 100000;
        for (int i=0; i<M; i++) {
            L[i] = sc.nextInt();
            if (L[i] > Lmax) Lmax = L[i];
            R[i] = sc.nextInt();
            if (R[i] < Rmin) Rmin = R[i];
        }
        for (int i=Lmax; i<=Rmin; i++) {
            cnt++;
        }
        System.out.println(cnt);
    } 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 cnt = 0; cnt 0 int Lmax = 0; Lmax 0 int Rmin = 100000; Rmin 100000 for (int i=0; i<M; i++) {
            L[i] = sc.nextInt();
            if (L[i] > Lmax) Lmax = L[i];
            R[i] = sc.nextInt();
            if (R[i] < Rmin) Rmin = R[i];
        } int i=0; int i=0; i 0 i<M i M i++ i++ i {
            L[i] = sc.nextInt();
            if (L[i] > Lmax) Lmax = L[i];
            R[i] = sc.nextInt();
            if (R[i] < Rmin) Rmin = R[i];
        } {
            L[i] = sc.nextInt();
            if (L[i] > Lmax) Lmax = L[i];
            R[i] = sc.nextInt();
            if (R[i] < Rmin) Rmin = R[i];
        } L[i] = sc.nextInt() L[i] L i sc.nextInt() sc.nextInt sc if (L[i] > Lmax) Lmax = L[i]; L[i] > Lmax L[i] L i Lmax Lmax = L[i] Lmax L[i] L i R[i] = sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc if (R[i] < Rmin) Rmin = R[i]; R[i] < Rmin R[i] R i Rmin Rmin = R[i] Rmin R[i] R i for (int i=Lmax; i<=Rmin; i++) {
            cnt++;
        } int i=Lmax; int i=Lmax; i Lmax i<=Rmin i Rmin i++ i++ i {
            cnt++;
        } {
            cnt++;
        } cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt 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];
        int[] R = new int[M];
        int cnt = 0;
        int Lmax = 0;
        int Rmin = 100000;
        for (int i=0; i<M; i++) {
            L[i] = sc.nextInt();
            if (L[i] > Lmax) Lmax = L[i];
            R[i] = sc.nextInt();
            if (R[i] < Rmin) Rmin = R[i];
        }
        for (int i=Lmax; i<=Rmin; i++) {
            cnt++;
        }
        System.out.println(cnt);
    }
} 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];
        int[] R = new int[M];
        int cnt = 0;
        int Lmax = 0;
        int Rmin = 100000;
        for (int i=0; i<M; i++) {
            L[i] = sc.nextInt();
            if (L[i] > Lmax) Lmax = L[i];
            R[i] = sc.nextInt();
            if (R[i] < Rmin) Rmin = R[i];
        }
        for (int i=Lmax; i<=Rmin; i++) {
            cnt++;
        }
        System.out.println(cnt);
    }
} 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[] L = new int[M];
        int[] R = new int[M];
        int cnt = 0;
        int Lmax = 0;
        int Rmin = 100000;
        for (int i=0; i<M; i++) {
            L[i] = sc.nextInt();
            if (L[i] > Lmax) Lmax = L[i];
            R[i] = sc.nextInt();
            if (R[i] < Rmin) Rmin = R[i];
        }
        for (int i=Lmax; i<=Rmin; i++) {
            cnt++;
        }
        System.out.println(cnt);
    }
}