import java.util.Scanner;

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];
		for(int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		int Lmax = L[0];
		int Rmax = R[0];
		int Lmin = L[0];
		int Rmin = R[0];
		for(int i = 0; i < M; i++) {
			if(Lmax < L[i]) Lmax = L[i];
			if(Lmin > L[i]) Lmin = L[i];
			if(Rmax < R[i]) Rmax = R[i];
			if(Rmin > R[i]) Rmin = R[i];

		}
		int ok = 0;

		for(int i =1; i<=N; i++) {
			if(Lmax<=i && i<=Rmin) ok++;


		}

		System.out.println(ok);


	}

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

		}
		int ok = 0;

		for(int i =1; i<=N; i++) {
			if(Lmax<=i && i<=Rmin) ok++;


		}

		System.out.println(ok);


	}

} 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];
		for(int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		int Lmax = L[0];
		int Rmax = R[0];
		int Lmin = L[0];
		int Rmin = R[0];
		for(int i = 0; i < M; i++) {
			if(Lmax < L[i]) Lmax = L[i];
			if(Lmin > L[i]) Lmin = L[i];
			if(Rmax < R[i]) Rmax = R[i];
			if(Rmin > R[i]) Rmin = R[i];

		}
		int ok = 0;

		for(int i =1; i<=N; i++) {
			if(Lmax<=i && i<=Rmin) ok++;


		}

		System.out.println(ok);


	} 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];
		for(int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		int Lmax = L[0];
		int Rmax = R[0];
		int Lmin = L[0];
		int Rmin = R[0];
		for(int i = 0; i < M; i++) {
			if(Lmax < L[i]) Lmax = L[i];
			if(Lmin > L[i]) Lmin = L[i];
			if(Rmax < R[i]) Rmax = R[i];
			if(Rmin > R[i]) Rmin = R[i];

		}
		int ok = 0;

		for(int i =1; i<=N; i++) {
			if(Lmax<=i && i<=Rmin) ok++;


		}

		System.out.println(ok);


	} 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 for(int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		} {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		} 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 int Lmax = L[0]; Lmax L[0] L 0 int Rmax = R[0]; Rmax R[0] R 0 int Lmin = L[0]; Lmin L[0] L 0 int Rmin = R[0]; Rmin R[0] R 0 for(int i = 0; i < M; i++) {
			if(Lmax < L[i]) Lmax = L[i];
			if(Lmin > L[i]) Lmin = L[i];
			if(Rmax < R[i]) Rmax = R[i];
			if(Rmin > R[i]) Rmin = R[i];

		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			if(Lmax < L[i]) Lmax = L[i];
			if(Lmin > L[i]) Lmin = L[i];
			if(Rmax < R[i]) Rmax = R[i];
			if(Rmin > R[i]) Rmin = R[i];

		} {
			if(Lmax < L[i]) Lmax = L[i];
			if(Lmin > L[i]) Lmin = L[i];
			if(Rmax < R[i]) Rmax = R[i];
			if(Rmin > R[i]) Rmin = R[i];

		} if(Lmax < L[i]) Lmax = L[i]; Lmax < L[i] Lmax L[i] L i Lmax = L[i] Lmax L[i] L i if(Lmin > L[i]) Lmin = L[i]; Lmin > L[i] Lmin L[i] L i Lmin = L[i] Lmin L[i] L i if(Rmax < R[i]) Rmax = R[i]; Rmax < R[i] Rmax R[i] R i Rmax = R[i] Rmax R[i] R i if(Rmin > R[i]) Rmin = R[i]; Rmin > R[i] Rmin R[i] R i Rmin = R[i] Rmin R[i] R i int ok = 0; ok 0 for(int i =1; i<=N; i++) {
			if(Lmax<=i && i<=Rmin) ok++;


		} int i =1; int i =1; i 1 i<=N i N i++ i++ i {
			if(Lmax<=i && i<=Rmin) ok++;


		} {
			if(Lmax<=i && i<=Rmin) ok++;


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

		}
		int ok = 0;

		for(int i =1; i<=N; i++) {
			if(Lmax<=i && i<=Rmin) ok++;


		}

		System.out.println(ok);


	}

} 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];
		for(int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		int Lmax = L[0];
		int Rmax = R[0];
		int Lmin = L[0];
		int Rmin = R[0];
		for(int i = 0; i < M; i++) {
			if(Lmax < L[i]) Lmax = L[i];
			if(Lmin > L[i]) Lmin = L[i];
			if(Rmax < R[i]) Rmax = R[i];
			if(Rmin > R[i]) Rmin = R[i];

		}
		int ok = 0;

		for(int i =1; i<=N; i++) {
			if(Lmax<=i && i<=Rmin) ok++;


		}

		System.out.println(ok);


	}

} Main
import java.util.Scanner;

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];
		for(int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		int Lmax = L[0];
		int Rmax = R[0];
		int Lmin = L[0];
		int Rmin = R[0];
		for(int i = 0; i < M; i++) {
			if(Lmax < L[i]) Lmax = L[i];
			if(Lmin > L[i]) Lmin = L[i];
			if(Rmax < R[i]) Rmax = R[i];
			if(Rmin > R[i]) Rmin = R[i];

		}
		int ok = 0;

		for(int i =1; i<=N; i++) {
			if(Lmax<=i && i<=Rmin) ok++;


		}

		System.out.println(ok);


	}

}