import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		String[] spl = S.split(" ");
		int N = Integer.parseInt(spl[0]);
		int M = Integer.parseInt(spl[1]);
		String Si = "";
		int[] L = new int[M];
		int[] R = new int[M];
		for(int i = 0;i < M;i++){
			 Si = sc.nextLine();
			String[] Sispl = Si.split(" ");
			L[i] = Integer.parseInt(Sispl[0]);
			R[i] =Integer.parseInt(Sispl[1]);
			Si = "";
		}
		sc.close();
		int Lmax = 1;
		int Rmin = N;
		int cnt = 0;
		for(int j = 0;j < M;j++){
			Lmax = Math.max(L[j], Lmax);
			Rmin = Math.min(R[j], Rmin);
		}
		for(int k = 1;k <= N;k++){
			if(k >= Lmax && k <= Rmin){
				cnt++;
			}
		}
		System.out.println(cnt);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		String[] spl = S.split(" ");
		int N = Integer.parseInt(spl[0]);
		int M = Integer.parseInt(spl[1]);
		String Si = "";
		int[] L = new int[M];
		int[] R = new int[M];
		for(int i = 0;i < M;i++){
			 Si = sc.nextLine();
			String[] Sispl = Si.split(" ");
			L[i] = Integer.parseInt(Sispl[0]);
			R[i] =Integer.parseInt(Sispl[1]);
			Si = "";
		}
		sc.close();
		int Lmax = 1;
		int Rmin = N;
		int cnt = 0;
		for(int j = 0;j < M;j++){
			Lmax = Math.max(L[j], Lmax);
			Rmin = Math.min(R[j], Rmin);
		}
		for(int k = 1;k <= N;k++){
			if(k >= Lmax && k <= Rmin){
				cnt++;
			}
		}
		System.out.println(cnt);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		String[] spl = S.split(" ");
		int N = Integer.parseInt(spl[0]);
		int M = Integer.parseInt(spl[1]);
		String Si = "";
		int[] L = new int[M];
		int[] R = new int[M];
		for(int i = 0;i < M;i++){
			 Si = sc.nextLine();
			String[] Sispl = Si.split(" ");
			L[i] = Integer.parseInt(Sispl[0]);
			R[i] =Integer.parseInt(Sispl[1]);
			Si = "";
		}
		sc.close();
		int Lmax = 1;
		int Rmin = N;
		int cnt = 0;
		for(int j = 0;j < M;j++){
			Lmax = Math.max(L[j], Lmax);
			Rmin = Math.min(R[j], Rmin);
		}
		for(int k = 1;k <= N;k++){
			if(k >= Lmax && k <= Rmin){
				cnt++;
			}
		}
		System.out.println(cnt);
	} main {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		String[] spl = S.split(" ");
		int N = Integer.parseInt(spl[0]);
		int M = Integer.parseInt(spl[1]);
		String Si = "";
		int[] L = new int[M];
		int[] R = new int[M];
		for(int i = 0;i < M;i++){
			 Si = sc.nextLine();
			String[] Sispl = Si.split(" ");
			L[i] = Integer.parseInt(Sispl[0]);
			R[i] =Integer.parseInt(Sispl[1]);
			Si = "";
		}
		sc.close();
		int Lmax = 1;
		int Rmin = N;
		int cnt = 0;
		for(int j = 0;j < M;j++){
			Lmax = Math.max(L[j], Lmax);
			Rmin = Math.min(R[j], Rmin);
		}
		for(int k = 1;k <= N;k++){
			if(k >= Lmax && k <= Rmin){
				cnt++;
			}
		}
		System.out.println(cnt);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String S = sc.nextLine(); S sc.nextLine() sc.nextLine sc String[] spl = S.split(" "); spl S.split(" ") S.split S " " int N = Integer.parseInt(spl[0]); N Integer.parseInt(spl[0]) Integer.parseInt Integer spl[0] spl 0 int M = Integer.parseInt(spl[1]); M Integer.parseInt(spl[1]) Integer.parseInt Integer spl[1] spl 1 String Si = ""; Si "" 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++){
			 Si = sc.nextLine();
			String[] Sispl = Si.split(" ");
			L[i] = Integer.parseInt(Sispl[0]);
			R[i] =Integer.parseInt(Sispl[1]);
			Si = "";
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			 Si = sc.nextLine();
			String[] Sispl = Si.split(" ");
			L[i] = Integer.parseInt(Sispl[0]);
			R[i] =Integer.parseInt(Sispl[1]);
			Si = "";
		} {
			 Si = sc.nextLine();
			String[] Sispl = Si.split(" ");
			L[i] = Integer.parseInt(Sispl[0]);
			R[i] =Integer.parseInt(Sispl[1]);
			Si = "";
		} Si = sc.nextLine() Si sc.nextLine() sc.nextLine sc String[] Sispl = Si.split(" "); Sispl Si.split(" ") Si.split Si " " L[i] = Integer.parseInt(Sispl[0]) L[i] L i Integer.parseInt(Sispl[0]) Integer.parseInt Integer Sispl[0] Sispl 0 R[i] =Integer.parseInt(Sispl[1]) R[i] R i Integer.parseInt(Sispl[1]) Integer.parseInt Integer Sispl[1] Sispl 1 Si = "" Si "" sc.close() sc.close sc int Lmax = 1; Lmax 1 int Rmin = N; Rmin N int cnt = 0; cnt 0 for(int j = 0;j < M;j++){
			Lmax = Math.max(L[j], Lmax);
			Rmin = Math.min(R[j], Rmin);
		} int j = 0; int j = 0; j 0 j < M j M j++ j++ j {
			Lmax = Math.max(L[j], Lmax);
			Rmin = Math.min(R[j], Rmin);
		} {
			Lmax = Math.max(L[j], Lmax);
			Rmin = Math.min(R[j], Rmin);
		} Lmax = Math.max(L[j], Lmax) Lmax Math.max(L[j], Lmax) Math.max Math L[j] L j Lmax Rmin = Math.min(R[j], Rmin) Rmin Math.min(R[j], Rmin) Math.min Math R[j] R j Rmin for(int k = 1;k <= N;k++){
			if(k >= Lmax && k <= Rmin){
				cnt++;
			}
		} int k = 1; int k = 1; k 1 k <= N k N k++ k++ k {
			if(k >= Lmax && k <= Rmin){
				cnt++;
			}
		} {
			if(k >= Lmax && k <= Rmin){
				cnt++;
			}
		} if(k >= Lmax && k <= Rmin){
				cnt++;
			} k >= Lmax && k <= Rmin k >= Lmax k Lmax k <= Rmin k Rmin {
				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);
		String S = sc.nextLine();
		String[] spl = S.split(" ");
		int N = Integer.parseInt(spl[0]);
		int M = Integer.parseInt(spl[1]);
		String Si = "";
		int[] L = new int[M];
		int[] R = new int[M];
		for(int i = 0;i < M;i++){
			 Si = sc.nextLine();
			String[] Sispl = Si.split(" ");
			L[i] = Integer.parseInt(Sispl[0]);
			R[i] =Integer.parseInt(Sispl[1]);
			Si = "";
		}
		sc.close();
		int Lmax = 1;
		int Rmin = N;
		int cnt = 0;
		for(int j = 0;j < M;j++){
			Lmax = Math.max(L[j], Lmax);
			Rmin = Math.min(R[j], Rmin);
		}
		for(int k = 1;k <= N;k++){
			if(k >= Lmax && k <= Rmin){
				cnt++;
			}
		}
		System.out.println(cnt);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		String[] spl = S.split(" ");
		int N = Integer.parseInt(spl[0]);
		int M = Integer.parseInt(spl[1]);
		String Si = "";
		int[] L = new int[M];
		int[] R = new int[M];
		for(int i = 0;i < M;i++){
			 Si = sc.nextLine();
			String[] Sispl = Si.split(" ");
			L[i] = Integer.parseInt(Sispl[0]);
			R[i] =Integer.parseInt(Sispl[1]);
			Si = "";
		}
		sc.close();
		int Lmax = 1;
		int Rmin = N;
		int cnt = 0;
		for(int j = 0;j < M;j++){
			Lmax = Math.max(L[j], Lmax);
			Rmin = Math.min(R[j], Rmin);
		}
		for(int k = 1;k <= N;k++){
			if(k >= Lmax && k <= Rmin){
				cnt++;
			}
		}
		System.out.println(cnt);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		String[] spl = S.split(" ");
		int N = Integer.parseInt(spl[0]);
		int M = Integer.parseInt(spl[1]);
		String Si = "";
		int[] L = new int[M];
		int[] R = new int[M];
		for(int i = 0;i < M;i++){
			 Si = sc.nextLine();
			String[] Sispl = Si.split(" ");
			L[i] = Integer.parseInt(Sispl[0]);
			R[i] =Integer.parseInt(Sispl[1]);
			Si = "";
		}
		sc.close();
		int Lmax = 1;
		int Rmin = N;
		int cnt = 0;
		for(int j = 0;j < M;j++){
			Lmax = Math.max(L[j], Lmax);
			Rmin = Math.min(R[j], Rmin);
		}
		for(int k = 1;k <= N;k++){
			if(k >= Lmax && k <= Rmin){
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}