import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, M;
		N = sc.nextInt();
		M = sc.nextInt();
		Integer L[] = new Integer[M];
		Integer R[] = new Integer[M];

		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(L, Collections.reverseOrder());
		Arrays.sort(R);
		if (R[0] - L[0] < 0) {
			System.out.println(0);
		} else {
			System.out.println(R[0] - L[0] + 1);
		}
	}
} import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, M;
		N = sc.nextInt();
		M = sc.nextInt();
		Integer L[] = new Integer[M];
		Integer R[] = new Integer[M];

		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(L, Collections.reverseOrder());
		Arrays.sort(R);
		if (R[0] - L[0] < 0) {
			System.out.println(0);
		} else {
			System.out.println(R[0] - L[0] + 1);
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, M;
		N = sc.nextInt();
		M = sc.nextInt();
		Integer L[] = new Integer[M];
		Integer R[] = new Integer[M];

		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(L, Collections.reverseOrder());
		Arrays.sort(R);
		if (R[0] - L[0] < 0) {
			System.out.println(0);
		} else {
			System.out.println(R[0] - L[0] + 1);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N, M;
		N = sc.nextInt();
		M = sc.nextInt();
		Integer L[] = new Integer[M];
		Integer R[] = new Integer[M];

		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(L, Collections.reverseOrder());
		Arrays.sort(R);
		if (R[0] - L[0] < 0) {
			System.out.println(0);
		} else {
			System.out.println(R[0] - L[0] + 1);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N N M; M N = sc.nextInt() N sc.nextInt() sc.nextInt sc M = sc.nextInt() M sc.nextInt() sc.nextInt sc Integer L[] = new Integer[M]; L new Integer[M] M Integer R[] = new Integer[M]; R new Integer[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 sc.close() sc.close sc Arrays.sort(L, Collections.reverseOrder()) Arrays.sort Arrays L Collections.reverseOrder() Collections.reverseOrder Collections Arrays.sort(R) Arrays.sort Arrays R if (R[0] - L[0] < 0) {
			System.out.println(0);
		} else {
			System.out.println(R[0] - L[0] + 1);
		} R[0] - L[0] < 0 R[0] - L[0] R[0] R 0 L[0] L 0 0 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(R[0] - L[0] + 1);
		} System.out.println(R[0] - L[0] + 1) System.out.println System.out System System.out R[0] - L[0] + 1 R[0] - L[0] R[0] R 0 L[0] L 0 1 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, M;
		N = sc.nextInt();
		M = sc.nextInt();
		Integer L[] = new Integer[M];
		Integer R[] = new Integer[M];

		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(L, Collections.reverseOrder());
		Arrays.sort(R);
		if (R[0] - L[0] < 0) {
			System.out.println(0);
		} else {
			System.out.println(R[0] - L[0] + 1);
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, M;
		N = sc.nextInt();
		M = sc.nextInt();
		Integer L[] = new Integer[M];
		Integer R[] = new Integer[M];

		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(L, Collections.reverseOrder());
		Arrays.sort(R);
		if (R[0] - L[0] < 0) {
			System.out.println(0);
		} else {
			System.out.println(R[0] - L[0] + 1);
		}
	}
} Main
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N, M;
		N = sc.nextInt();
		M = sc.nextInt();
		Integer L[] = new Integer[M];
		Integer R[] = new Integer[M];

		for (int i = 0; i < M; i++) {
			L[i] = sc.nextInt();
			R[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(L, Collections.reverseOrder());
		Arrays.sort(R);
		if (R[0] - L[0] < 0) {
			System.out.println(0);
		} else {
			System.out.println(R[0] - L[0] + 1);
		}
	}
}
