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();
		int max = 1;
		int min = n + 1;
		int li;
		int ri;
		for (int i = 1; i <= m; i++) {
			li = sc.nextInt();
			ri = sc.nextInt();

			if (li > max) {
				max = li;
			}
			if (ri < min) {
				min = ri;
			}
		}

		int ans = min - max + 1;
		if (ans >= 0) {
			System.out.println(ans);
		} else {

			System.out.println(0);
		}
	}
} 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();
		int max = 1;
		int min = n + 1;
		int li;
		int ri;
		for (int i = 1; i <= m; i++) {
			li = sc.nextInt();
			ri = sc.nextInt();

			if (li > max) {
				max = li;
			}
			if (ri < min) {
				min = ri;
			}
		}

		int ans = min - max + 1;
		if (ans >= 0) {
			System.out.println(ans);
		} else {

			System.out.println(0);
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int max = 1;
		int min = n + 1;
		int li;
		int ri;
		for (int i = 1; i <= m; i++) {
			li = sc.nextInt();
			ri = sc.nextInt();

			if (li > max) {
				max = li;
			}
			if (ri < min) {
				min = ri;
			}
		}

		int ans = min - max + 1;
		if (ans >= 0) {
			System.out.println(ans);
		} else {

			System.out.println(0);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int max = 1;
		int min = n + 1;
		int li;
		int ri;
		for (int i = 1; i <= m; i++) {
			li = sc.nextInt();
			ri = sc.nextInt();

			if (li > max) {
				max = li;
			}
			if (ri < min) {
				min = ri;
			}
		}

		int ans = min - max + 1;
		if (ans >= 0) {
			System.out.println(ans);
		} else {

			System.out.println(0);
		}
	} 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 max = 1; max 1 int min = n + 1; min n + 1 n 1 int li; li int ri; ri for (int i = 1; i <= m; i++) {
			li = sc.nextInt();
			ri = sc.nextInt();

			if (li > max) {
				max = li;
			}
			if (ri < min) {
				min = ri;
			}
		} int i = 1; int i = 1; i 1 i <= m i m i++ i++ i {
			li = sc.nextInt();
			ri = sc.nextInt();

			if (li > max) {
				max = li;
			}
			if (ri < min) {
				min = ri;
			}
		} {
			li = sc.nextInt();
			ri = sc.nextInt();

			if (li > max) {
				max = li;
			}
			if (ri < min) {
				min = ri;
			}
		} li = sc.nextInt() li sc.nextInt() sc.nextInt sc ri = sc.nextInt() ri sc.nextInt() sc.nextInt sc if (li > max) {
				max = li;
			} li > max li max {
				max = li;
			} max = li max li if (ri < min) {
				min = ri;
			} ri < min ri min {
				min = ri;
			} min = ri min ri int ans = min - max + 1; ans min - max + 1 min - max min max 1 if (ans >= 0) {
			System.out.println(ans);
		} else {

			System.out.println(0);
		} ans >= 0 ans 0 {
			System.out.println(ans);
		} System.out.println(ans) System.out.println System.out System System.out ans {

			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 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();
		int max = 1;
		int min = n + 1;
		int li;
		int ri;
		for (int i = 1; i <= m; i++) {
			li = sc.nextInt();
			ri = sc.nextInt();

			if (li > max) {
				max = li;
			}
			if (ri < min) {
				min = ri;
			}
		}

		int ans = min - max + 1;
		if (ans >= 0) {
			System.out.println(ans);
		} else {

			System.out.println(0);
		}
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int max = 1;
		int min = n + 1;
		int li;
		int ri;
		for (int i = 1; i <= m; i++) {
			li = sc.nextInt();
			ri = sc.nextInt();

			if (li > max) {
				max = li;
			}
			if (ri < min) {
				min = ri;
			}
		}

		int ans = min - max + 1;
		if (ans >= 0) {
			System.out.println(ans);
		} else {

			System.out.println(0);
		}
	}
} 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();
		int max = 1;
		int min = n + 1;
		int li;
		int ri;
		for (int i = 1; i <= m; i++) {
			li = sc.nextInt();
			ri = sc.nextInt();

			if (li > max) {
				max = li;
			}
			if (ri < min) {
				min = ri;
			}
		}

		int ans = min - max + 1;
		if (ans >= 0) {
			System.out.println(ans);
		} else {

			System.out.println(0);
		}
	}
}
