import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int left = 1, right = N;
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			left = Math.max(left, L);
			right = Math.min(right, R);
		}
		sc.close();
		// System.out.println(left + " <= " + right);
		System.out.println(left <= right ? right - left + 1 : 0);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int left = 1, right = N;
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			left = Math.max(left, L);
			right = Math.min(right, R);
		}
		sc.close();
		// System.out.println(left + " <= " + right);
		System.out.println(left <= right ? right - left + 1 : 0);
	}
} Main public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int left = 1, right = N;
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			left = Math.max(left, L);
			right = Math.min(right, R);
		}
		sc.close();
		// System.out.println(left + " <= " + right);
		System.out.println(left <= right ? right - left + 1 : 0);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int left = 1, right = N;
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			left = Math.max(left, L);
			right = Math.min(right, R);
		}
		sc.close();
		// System.out.println(left + " <= " + right);
		System.out.println(left <= right ? right - left + 1 : 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 right = N; right N for(int i = 0; i < M; i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			left = Math.max(left, L);
			right = Math.min(right, R);
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			int L = sc.nextInt();
			int R = sc.nextInt();
			left = Math.max(left, L);
			right = Math.min(right, R);
		} {
			int L = sc.nextInt();
			int R = sc.nextInt();
			left = Math.max(left, L);
			right = Math.min(right, R);
		} int L = sc.nextInt(); L sc.nextInt() sc.nextInt sc int R = sc.nextInt(); R sc.nextInt() sc.nextInt sc left = Math.max(left, L) left Math.max(left, L) Math.max Math left L right = Math.min(right, R) right Math.min(right, R) Math.min Math right R sc.close() sc.close sc System.out.println(left <= right ? right - left + 1 : 0) System.out.println System.out System System.out left <= right ? right - left + 1 : 0 left <= right left right right - left + 1 right - left right left 1 0 final String[] args args public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int left = 1, right = N;
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			left = Math.max(left, L);
			right = Math.min(right, R);
		}
		sc.close();
		// System.out.println(left + " <= " + right);
		System.out.println(left <= right ? right - left + 1 : 0);
	}
} public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int left = 1, right = N;
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			left = Math.max(left, L);
			right = Math.min(right, R);
		}
		sc.close();
		// System.out.println(left + " <= " + right);
		System.out.println(left <= right ? right - left + 1 : 0);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int left = 1, right = N;
		for(int i = 0; i < M; i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			left = Math.max(left, L);
			right = Math.min(right, R);
		}
		sc.close();
		// System.out.println(left + " <= " + right);
		System.out.println(left <= right ? right - left + 1 : 0);
	}
}