
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		long left=Long.MIN_VALUE;
		long right=Long.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			int A = sc.nextInt();
			int B = sc.nextInt();

			left = Math.max(left, A);
			right = Math.min(right, B);

			if (left > right) {
				System.out.println(0);
				break;
			}

			if (i == M-1) {
				System.out.println(right-left+1);
				break;
			}

		}

	}
}

 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();
		int M = sc.nextInt();

		long left=Long.MIN_VALUE;
		long right=Long.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			int A = sc.nextInt();
			int B = sc.nextInt();

			left = Math.max(left, A);
			right = Math.min(right, B);

			if (left > right) {
				System.out.println(0);
				break;
			}

			if (i == M-1) {
				System.out.println(right-left+1);
				break;
			}

		}

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

		long left=Long.MIN_VALUE;
		long right=Long.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			int A = sc.nextInt();
			int B = sc.nextInt();

			left = Math.max(left, A);
			right = Math.min(right, B);

			if (left > right) {
				System.out.println(0);
				break;
			}

			if (i == M-1) {
				System.out.println(right-left+1);
				break;
			}

		}

	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		long left=Long.MIN_VALUE;
		long right=Long.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			int A = sc.nextInt();
			int B = sc.nextInt();

			left = Math.max(left, A);
			right = Math.min(right, B);

			if (left > right) {
				System.out.println(0);
				break;
			}

			if (i == M-1) {
				System.out.println(right-left+1);
				break;
			}

		}

	} 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 long left=Long.MIN_VALUE; left Long.MIN_VALUE Long Long.MIN_VALUE long right=Long.MAX_VALUE; right Long.MAX_VALUE Long Long.MAX_VALUE for (int i = 0; i < M; i++) {
			int A = sc.nextInt();
			int B = sc.nextInt();

			left = Math.max(left, A);
			right = Math.min(right, B);

			if (left > right) {
				System.out.println(0);
				break;
			}

			if (i == M-1) {
				System.out.println(right-left+1);
				break;
			}

		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			int A = sc.nextInt();
			int B = sc.nextInt();

			left = Math.max(left, A);
			right = Math.min(right, B);

			if (left > right) {
				System.out.println(0);
				break;
			}

			if (i == M-1) {
				System.out.println(right-left+1);
				break;
			}

		} {
			int A = sc.nextInt();
			int B = sc.nextInt();

			left = Math.max(left, A);
			right = Math.min(right, B);

			if (left > right) {
				System.out.println(0);
				break;
			}

			if (i == M-1) {
				System.out.println(right-left+1);
				break;
			}

		} int A = sc.nextInt(); A sc.nextInt() sc.nextInt sc int B = sc.nextInt(); B sc.nextInt() sc.nextInt sc left = Math.max(left, A) left Math.max(left, A) Math.max Math left A right = Math.min(right, B) right Math.min(right, B) Math.min Math right B if (left > right) {
				System.out.println(0);
				break;
			} left > right left right {
				System.out.println(0);
				break;
			} System.out.println(0) System.out.println System.out System System.out 0 break; if (i == M-1) {
				System.out.println(right-left+1);
				break;
			} i == M-1 i M-1 M 1 {
				System.out.println(right-left+1);
				break;
			} System.out.println(right-left+1) System.out.println System.out System System.out right-left+1 right-left right left 1 break; String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		long left=Long.MIN_VALUE;
		long right=Long.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			int A = sc.nextInt();
			int B = sc.nextInt();

			left = Math.max(left, A);
			right = Math.min(right, B);

			if (left > right) {
				System.out.println(0);
				break;
			}

			if (i == M-1) {
				System.out.println(right-left+1);
				break;
			}

		}

	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		long left=Long.MIN_VALUE;
		long right=Long.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			int A = sc.nextInt();
			int B = sc.nextInt();

			left = Math.max(left, A);
			right = Math.min(right, B);

			if (left > right) {
				System.out.println(0);
				break;
			}

			if (i == M-1) {
				System.out.println(right-left+1);
				break;
			}

		}

	}
} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		long left=Long.MIN_VALUE;
		long right=Long.MAX_VALUE;
		for (int i = 0; i < M; i++) {
			int A = sc.nextInt();
			int B = sc.nextInt();

			left = Math.max(left, A);
			right = Math.min(right, B);

			if (left > right) {
				System.out.println(0);
				break;
			}

			if (i == M-1) {
				System.out.println(right-left+1);
				break;
			}

		}

	}
}


