import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int count = 0;
		int M = sc.nextInt();

		int L[] = new int[M];
		int R[] = new int[M];

		int maxL = 1;
		int minR = 100000;

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

			if (maxL <= L[j]) {
				maxL = L[j];
			}

			if (minR >= R[j]) {
				minR = R[j];
			}

		}

		for (int i = 1; i <= N; i++) {
			if (maxL <= i && i <= minR) {
				count++;
			}
		}

		System.out.print(count);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int count = 0;
		int M = sc.nextInt();

		int L[] = new int[M];
		int R[] = new int[M];

		int maxL = 1;
		int minR = 100000;

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

			if (maxL <= L[j]) {
				maxL = L[j];
			}

			if (minR >= R[j]) {
				minR = R[j];
			}

		}

		for (int i = 1; i <= N; i++) {
			if (maxL <= i && i <= minR) {
				count++;
			}
		}

		System.out.print(count);
	}
} Main public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int count = 0;
		int M = sc.nextInt();

		int L[] = new int[M];
		int R[] = new int[M];

		int maxL = 1;
		int minR = 100000;

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

			if (maxL <= L[j]) {
				maxL = L[j];
			}

			if (minR >= R[j]) {
				minR = R[j];
			}

		}

		for (int i = 1; i <= N; i++) {
			if (maxL <= i && i <= minR) {
				count++;
			}
		}

		System.out.print(count);
	} main {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int count = 0;
		int M = sc.nextInt();

		int L[] = new int[M];
		int R[] = new int[M];

		int maxL = 1;
		int minR = 100000;

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

			if (maxL <= L[j]) {
				maxL = L[j];
			}

			if (minR >= R[j]) {
				minR = R[j];
			}

		}

		for (int i = 1; i <= N; i++) {
			if (maxL <= i && i <= minR) {
				count++;
			}
		}

		System.out.print(count);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int count = 0; count 0 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 int maxL = 1; maxL 1 int minR = 100000; minR 100000 for (int j = 0; j < M; j++) {
			L[j] = sc.nextInt();
			R[j] = sc.nextInt();

			if (maxL <= L[j]) {
				maxL = L[j];
			}

			if (minR >= R[j]) {
				minR = R[j];
			}

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

			if (maxL <= L[j]) {
				maxL = L[j];
			}

			if (minR >= R[j]) {
				minR = R[j];
			}

		} {
			L[j] = sc.nextInt();
			R[j] = sc.nextInt();

			if (maxL <= L[j]) {
				maxL = L[j];
			}

			if (minR >= R[j]) {
				minR = R[j];
			}

		} L[j] = sc.nextInt() L[j] L j sc.nextInt() sc.nextInt sc R[j] = sc.nextInt() R[j] R j sc.nextInt() sc.nextInt sc if (maxL <= L[j]) {
				maxL = L[j];
			} maxL <= L[j] maxL L[j] L j {
				maxL = L[j];
			} maxL = L[j] maxL L[j] L j if (minR >= R[j]) {
				minR = R[j];
			} minR >= R[j] minR R[j] R j {
				minR = R[j];
			} minR = R[j] minR R[j] R j for (int i = 1; i <= N; i++) {
			if (maxL <= i && i <= minR) {
				count++;
			}
		} int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
			if (maxL <= i && i <= minR) {
				count++;
			}
		} {
			if (maxL <= i && i <= minR) {
				count++;
			}
		} if (maxL <= i && i <= minR) {
				count++;
			} maxL <= i && i <= minR maxL <= i maxL i i <= minR i minR {
				count++;
			} count++ count System.out.print(count) System.out.print System.out System System.out count String arg[] arg public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int count = 0;
		int M = sc.nextInt();

		int L[] = new int[M];
		int R[] = new int[M];

		int maxL = 1;
		int minR = 100000;

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

			if (maxL <= L[j]) {
				maxL = L[j];
			}

			if (minR >= R[j]) {
				minR = R[j];
			}

		}

		for (int i = 1; i <= N; i++) {
			if (maxL <= i && i <= minR) {
				count++;
			}
		}

		System.out.print(count);
	}
} public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int count = 0;
		int M = sc.nextInt();

		int L[] = new int[M];
		int R[] = new int[M];

		int maxL = 1;
		int minR = 100000;

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

			if (maxL <= L[j]) {
				maxL = L[j];
			}

			if (minR >= R[j]) {
				minR = R[j];
			}

		}

		for (int i = 1; i <= N; i++) {
			if (maxL <= i && i <= minR) {
				count++;
			}
		}

		System.out.print(count);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int count = 0;
		int M = sc.nextInt();

		int L[] = new int[M];
		int R[] = new int[M];

		int maxL = 1;
		int minR = 100000;

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

			if (maxL <= L[j]) {
				maxL = L[j];
			}

			if (minR >= R[j]) {
				minR = R[j];
			}

		}

		for (int i = 1; i <= N; i++) {
			if (maxL <= i && i <= minR) {
				count++;
			}
		}

		System.out.print(count);
	}
}