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 left = 1;
		int right = N;

		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);
		}
		int answer = right - left + 1;
		if (answer > 0) {
			System.out.println(answer);
		} 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 left = 1;
		int right = N;

		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);
		}
		int answer = right - left + 1;
		if (answer > 0) {
			System.out.println(answer);
		} 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 left = 1;
		int right = N;

		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);
		}
		int answer = right - left + 1;
		if (answer > 0) {
			System.out.println(answer);
		} else {
			System.out.println(0);
		}

	} main {

		Scanner sc = new Scanner(System.in);

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

		int left = 1;
		int right = N;

		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);
		}
		int answer = right - left + 1;
		if (answer > 0) {
			System.out.println(answer);
		} 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 left = 1; left 1 int right = N; right N 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);
		} 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);
		} {
			int a = sc.nextInt();
			int b = sc.nextInt();
			left = Math.max(left, a);
			right = Math.min(right, b);
		} 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 int answer = right - left + 1; answer right - left + 1 right - left right left 1 if (answer > 0) {
			System.out.println(answer);
		} else {
			System.out.println(0);
		} answer > 0 answer 0 {
			System.out.println(answer);
		} System.out.println(answer) System.out.println System.out System System.out answer {
			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 left = 1;
		int right = N;

		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);
		}
		int answer = right - left + 1;
		if (answer > 0) {
			System.out.println(answer);
		} 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 left = 1;
		int right = N;

		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);
		}
		int answer = right - left + 1;
		if (answer > 0) {
			System.out.println(answer);
		} 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 left = 1;
		int right = N;

		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);
		}
		int answer = right - left + 1;
		if (answer > 0) {
			System.out.println(answer);
		} else {
			System.out.println(0);
		}

	}

}