import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		int L[] = new int[M], R[] = new int[M];
		int min = 99999999, max = 0;
		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			min = Math.min(min, R[i]);
			max = Math.max(max, L[i]);
		}
		if (min - max >= 0) {
			System.out.println(min - max + 1);
		} else {
			System.out.println(0);
		}
		sc.close();
	}
} 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(), M = sc.nextInt();
		int L[] = new int[M], R[] = new int[M];
		int min = 99999999, max = 0;
		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			min = Math.min(min, R[i]);
			max = Math.max(max, L[i]);
		}
		if (min - max >= 0) {
			System.out.println(min - max + 1);
		} else {
			System.out.println(0);
		}
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		int L[] = new int[M], R[] = new int[M];
		int min = 99999999, max = 0;
		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			min = Math.min(min, R[i]);
			max = Math.max(max, L[i]);
		}
		if (min - max >= 0) {
			System.out.println(min - max + 1);
		} else {
			System.out.println(0);
		}
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		int L[] = new int[M], R[] = new int[M];
		int min = 99999999, max = 0;
		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			min = Math.min(min, R[i]);
			max = Math.max(max, L[i]);
		}
		if (min - max >= 0) {
			System.out.println(min - max + 1);
		} else {
			System.out.println(0);
		}
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt() N sc.nextInt() sc.nextInt sc M = sc.nextInt(); M sc.nextInt() sc.nextInt sc int L[] = new int[M] L new int[M] M R[] = new int[M]; R new int[M] M int min = 99999999 min 99999999 max = 0; max 0 for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			min = Math.min(min, R[i]);
			max = Math.max(max, L[i]);
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			min = Math.min(min, R[i]);
			max = Math.max(max, L[i]);
		} {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			min = Math.min(min, R[i]);
			max = Math.max(max, L[i]);
		} 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 min = Math.min(min, R[i]) min Math.min(min, R[i]) Math.min Math min R[i] R i max = Math.max(max, L[i]) max Math.max(max, L[i]) Math.max Math max L[i] L i if (min - max >= 0) {
			System.out.println(min - max + 1);
		} else {
			System.out.println(0);
		} min - max >= 0 min - max min max 0 {
			System.out.println(min - max + 1);
		} System.out.println(min - max + 1) System.out.println System.out System System.out min - max + 1 min - max min max 1 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		int L[] = new int[M], R[] = new int[M];
		int min = 99999999, max = 0;
		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			min = Math.min(min, R[i]);
			max = Math.max(max, L[i]);
		}
		if (min - max >= 0) {
			System.out.println(min - max + 1);
		} else {
			System.out.println(0);
		}
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		int L[] = new int[M], R[] = new int[M];
		int min = 99999999, max = 0;
		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			min = Math.min(min, R[i]);
			max = Math.max(max, L[i]);
		}
		if (min - max >= 0) {
			System.out.println(min - max + 1);
		} else {
			System.out.println(0);
		}
		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), M = sc.nextInt();
		int L[] = new int[M], R[] = new int[M];
		int min = 99999999, max = 0;
		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
			min = Math.min(min, R[i]);
			max = Math.max(max, L[i]);
		}
		if (min - max >= 0) {
			System.out.println(min - max + 1);
		} else {
			System.out.println(0);
		}
		sc.close();
	}
}
