import java.util.Scanner;

class Pair<F, S>{
	F first;
	S second;
	public Pair(F f, S s) {
		first = f;
		second = s;
	}
}

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] cover_gates = new int[N + 1];
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt() - 1;
			int R = sc.nextInt();
			cover_gates[L]++;
			cover_gates[R]--;
		}
		for(int i = 1; i <= N; i++) {
			cover_gates[i] += cover_gates[i - 1];
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			if(cover_gates[i] == M) cnt++;
		}
		System.out.println(cnt);
	}
} import java.util.Scanner; Scanner java.util class Pair<F, S>{
	F first;
	S second;
	public Pair(F f, S s) {
		first = f;
		second = s;
	}
} Pair F first; first S second; second public Pair(F f, S s) {
		first = f;
		second = s;
	} Pair {
		first = f;
		second = s;
	} first = f first f second = s second s F f f S s s class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] cover_gates = new int[N + 1];
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt() - 1;
			int R = sc.nextInt();
			cover_gates[L]++;
			cover_gates[R]--;
		}
		for(int i = 1; i <= N; i++) {
			cover_gates[i] += cover_gates[i - 1];
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			if(cover_gates[i] == M) 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[] cover_gates = new int[N + 1];
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt() - 1;
			int R = sc.nextInt();
			cover_gates[L]++;
			cover_gates[R]--;
		}
		for(int i = 1; i <= N; i++) {
			cover_gates[i] += cover_gates[i - 1];
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			if(cover_gates[i] == M) cnt++;
		}
		System.out.println(cnt);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] cover_gates = new int[N + 1];
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt() - 1;
			int R = sc.nextInt();
			cover_gates[L]++;
			cover_gates[R]--;
		}
		for(int i = 1; i <= N; i++) {
			cover_gates[i] += cover_gates[i - 1];
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			if(cover_gates[i] == M) 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[] cover_gates = new int[N + 1]; cover_gates new int[N + 1] N + 1 N 1 for(int i = 0; i < M; i++) {
			int L = sc.nextInt() - 1;
			int R = sc.nextInt();
			cover_gates[L]++;
			cover_gates[R]--;
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			int L = sc.nextInt() - 1;
			int R = sc.nextInt();
			cover_gates[L]++;
			cover_gates[R]--;
		} {
			int L = sc.nextInt() - 1;
			int R = sc.nextInt();
			cover_gates[L]++;
			cover_gates[R]--;
		} int L = sc.nextInt() - 1; L sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 int R = sc.nextInt(); R sc.nextInt() sc.nextInt sc cover_gates[L]++ cover_gates[L] cover_gates L cover_gates[R]-- cover_gates[R] cover_gates R for(int i = 1; i <= N; i++) {
			cover_gates[i] += cover_gates[i - 1];
		} int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
			cover_gates[i] += cover_gates[i - 1];
		} {
			cover_gates[i] += cover_gates[i - 1];
		} cover_gates[i] += cover_gates[i - 1] cover_gates[i] cover_gates i cover_gates[i - 1] cover_gates i - 1 i 1 int cnt = 0; cnt 0 for(int i = 0; i < N; i++) {
			if(cover_gates[i] == M) cnt++;
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if(cover_gates[i] == M) cnt++;
		} {
			if(cover_gates[i] == M) cnt++;
		} if(cover_gates[i] == M) cnt++; cover_gates[i] == M cover_gates[i] cover_gates i M cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String args[] args
import java.util.Scanner;

class Pair<F, S>{
	F first;
	S second;
	public Pair(F f, S s) {
		first = f;
		second = s;
	}
}

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] cover_gates = new int[N + 1];
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt() - 1;
			int R = sc.nextInt();
			cover_gates[L]++;
			cover_gates[R]--;
		}
		for(int i = 1; i <= N; i++) {
			cover_gates[i] += cover_gates[i - 1];
		}
		int cnt = 0;
		for(int i = 0; i < N; i++) {
			if(cover_gates[i] == M) cnt++;
		}
		System.out.println(cnt);
	}
}