import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] l = new int[m];
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		Arrays.sort(r);
		Arrays.sort(l);
		
		int min = l[m - 1];
		int max = r[0];
		int count = 0;

		for (int i = 1; i <= n; i++) {
			if (min <=i && i <= max) {
				count++;
			}
		}
		System.out.println(count);
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] l = new int[m];
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		Arrays.sort(r);
		Arrays.sort(l);
		
		int min = l[m - 1];
		int max = r[0];
		int count = 0;

		for (int i = 1; i <= n; i++) {
			if (min <=i && i <= max) {
				count++;
			}
		}
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] l = new int[m];
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		Arrays.sort(r);
		Arrays.sort(l);
		
		int min = l[m - 1];
		int max = r[0];
		int count = 0;

		for (int i = 1; i <= n; i++) {
			if (min <=i && i <= max) {
				count++;
			}
		}
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] l = new int[m];
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		Arrays.sort(r);
		Arrays.sort(l);
		
		int min = l[m - 1];
		int max = r[0];
		int count = 0;

		for (int i = 1; i <= n; i++) {
			if (min <=i && i <= max) {
				count++;
			}
		}
		System.out.println(count);
	} 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[] l = new int[m]; l new int[m] m int[] r = new int[m]; r new int[m] m for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		} {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		} l[i] = sc.nextInt() l[i] l i sc.nextInt() sc.nextInt sc r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc Arrays.sort(r) Arrays.sort Arrays r Arrays.sort(l) Arrays.sort Arrays l int min = l[m - 1]; min l[m - 1] l m - 1 m 1 int max = r[0]; max r[0] r 0 int count = 0; count 0 for (int i = 1; i <= n; i++) {
			if (min <=i && i <= max) {
				count++;
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if (min <=i && i <= max) {
				count++;
			}
		} {
			if (min <=i && i <= max) {
				count++;
			}
		} if (min <=i && i <= max) {
				count++;
			} min <=i && i <= max min <=i min i i <= max i max {
				count++;
			} count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] l = new int[m];
		int[] r = new int[m];
		for (int i = 0; i < m; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		Arrays.sort(r);
		Arrays.sort(l);
		
		int min = l[m - 1];
		int max = r[0];
		int count = 0;

		for (int i = 1; i <= n; i++) {
			if (min <=i && i <= max) {
				count++;
			}
		}
		System.out.println(count);
	}
}