import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int n,m;

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		m = sc.nextInt();

		int max = 1;
		int min = n;
		int ans = 0;

		for (int i = 0; i < m; i++) {

			int maxTmp,minTmp;

			maxTmp = sc.nextInt();
			minTmp = sc.nextInt();

			max = Math.max(max, maxTmp);
			min = Math.min(min, minTmp);

		}

		ans = min - max + 1;

		if (ans < 1) {
			System.out.println(0);
		} else {
			System.out.println(ans);
		}

	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		int n,m;

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		m = sc.nextInt();

		int max = 1;
		int min = n;
		int ans = 0;

		for (int i = 0; i < m; i++) {

			int maxTmp,minTmp;

			maxTmp = sc.nextInt();
			minTmp = sc.nextInt();

			max = Math.max(max, maxTmp);
			min = Math.min(min, minTmp);

		}

		ans = min - max + 1;

		if (ans < 1) {
			System.out.println(0);
		} else {
			System.out.println(ans);
		}

	}
} Main public static void main(String[] args) {

		int n,m;

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		m = sc.nextInt();

		int max = 1;
		int min = n;
		int ans = 0;

		for (int i = 0; i < m; i++) {

			int maxTmp,minTmp;

			maxTmp = sc.nextInt();
			minTmp = sc.nextInt();

			max = Math.max(max, maxTmp);
			min = Math.min(min, minTmp);

		}

		ans = min - max + 1;

		if (ans < 1) {
			System.out.println(0);
		} else {
			System.out.println(ans);
		}

	} main {

		int n,m;

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		m = sc.nextInt();

		int max = 1;
		int min = n;
		int ans = 0;

		for (int i = 0; i < m; i++) {

			int maxTmp,minTmp;

			maxTmp = sc.nextInt();
			minTmp = sc.nextInt();

			max = Math.max(max, maxTmp);
			min = Math.min(min, minTmp);

		}

		ans = min - max + 1;

		if (ans < 1) {
			System.out.println(0);
		} else {
			System.out.println(ans);
		}

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

			int maxTmp,minTmp;

			maxTmp = sc.nextInt();
			minTmp = sc.nextInt();

			max = Math.max(max, maxTmp);
			min = Math.min(min, minTmp);

		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {

			int maxTmp,minTmp;

			maxTmp = sc.nextInt();
			minTmp = sc.nextInt();

			max = Math.max(max, maxTmp);
			min = Math.min(min, minTmp);

		} {

			int maxTmp,minTmp;

			maxTmp = sc.nextInt();
			minTmp = sc.nextInt();

			max = Math.max(max, maxTmp);
			min = Math.min(min, minTmp);

		} int maxTmp maxTmp minTmp; minTmp maxTmp = sc.nextInt() maxTmp sc.nextInt() sc.nextInt sc minTmp = sc.nextInt() minTmp sc.nextInt() sc.nextInt sc max = Math.max(max, maxTmp) max Math.max(max, maxTmp) Math.max Math max maxTmp min = Math.min(min, minTmp) min Math.min(min, minTmp) Math.min Math min minTmp ans = min - max + 1 ans min - max + 1 min - max min max 1 if (ans < 1) {
			System.out.println(0);
		} else {
			System.out.println(ans);
		} ans < 1 ans 1 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(ans);
		} System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

	public static void main(String[] args) {

		int n,m;

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		m = sc.nextInt();

		int max = 1;
		int min = n;
		int ans = 0;

		for (int i = 0; i < m; i++) {

			int maxTmp,minTmp;

			maxTmp = sc.nextInt();
			minTmp = sc.nextInt();

			max = Math.max(max, maxTmp);
			min = Math.min(min, minTmp);

		}

		ans = min - max + 1;

		if (ans < 1) {
			System.out.println(0);
		} else {
			System.out.println(ans);
		}

	}
} public class Main {

	public static void main(String[] args) {

		int n,m;

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		m = sc.nextInt();

		int max = 1;
		int min = n;
		int ans = 0;

		for (int i = 0; i < m; i++) {

			int maxTmp,minTmp;

			maxTmp = sc.nextInt();
			minTmp = sc.nextInt();

			max = Math.max(max, maxTmp);
			min = Math.min(min, minTmp);

		}

		ans = min - max + 1;

		if (ans < 1) {
			System.out.println(0);
		} else {
			System.out.println(ans);
		}

	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int n,m;

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		m = sc.nextInt();

		int max = 1;
		int min = n;
		int ans = 0;

		for (int i = 0; i < m; i++) {

			int maxTmp,minTmp;

			maxTmp = sc.nextInt();
			minTmp = sc.nextInt();

			max = Math.max(max, maxTmp);
			min = Math.min(min, minTmp);

		}

		ans = min - max + 1;

		if (ans < 1) {
			System.out.println(0);
		} else {
			System.out.println(ans);
		}

	}
}
