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 maxL = 0;
		int minR = 100_009;
		
		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			maxL = Math.max(maxL, l);
			minR = Math.min(minR, r);
		}
		
		int dif = minR - maxL;
		int ans = Math.max(dif + 1, 0);
		
		System.out.println(ans);
		

	}
} 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 maxL = 0;
		int minR = 100_009;
		
		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			maxL = Math.max(maxL, l);
			minR = Math.min(minR, r);
		}
		
		int dif = minR - maxL;
		int ans = Math.max(dif + 1, 0);
		
		System.out.println(ans);
		

	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int maxL = 0;
		int minR = 100_009;
		
		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			maxL = Math.max(maxL, l);
			minR = Math.min(minR, r);
		}
		
		int dif = minR - maxL;
		int ans = Math.max(dif + 1, 0);
		
		System.out.println(ans);
		

	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int maxL = 0;
		int minR = 100_009;
		
		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			maxL = Math.max(maxL, l);
			minR = Math.min(minR, r);
		}
		
		int dif = minR - maxL;
		int ans = Math.max(dif + 1, 0);
		
		System.out.println(ans);
		

	} 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 maxL = 0; maxL 0 int minR = 100_009; minR 100_009 for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			maxL = Math.max(maxL, l);
			minR = Math.min(minR, r);
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			int l = sc.nextInt();
			int r = sc.nextInt();
			maxL = Math.max(maxL, l);
			minR = Math.min(minR, r);
		} {
			int l = sc.nextInt();
			int r = sc.nextInt();
			maxL = Math.max(maxL, l);
			minR = Math.min(minR, r);
		} int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc maxL = Math.max(maxL, l) maxL Math.max(maxL, l) Math.max Math maxL l minR = Math.min(minR, r) minR Math.min(minR, r) Math.min Math minR r int dif = minR - maxL; dif minR - maxL minR maxL int ans = Math.max(dif + 1, 0); ans Math.max(dif + 1, 0) Math.max Math dif + 1 dif 1 0 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) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int maxL = 0;
		int minR = 100_009;
		
		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			maxL = Math.max(maxL, l);
			minR = Math.min(minR, r);
		}
		
		int dif = minR - maxL;
		int ans = Math.max(dif + 1, 0);
		
		System.out.println(ans);
		

	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int maxL = 0;
		int minR = 100_009;
		
		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			maxL = Math.max(maxL, l);
			minR = Math.min(minR, r);
		}
		
		int dif = minR - maxL;
		int ans = Math.max(dif + 1, 0);
		
		System.out.println(ans);
		

	}
} 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 maxL = 0;
		int minR = 100_009;
		
		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			maxL = Math.max(maxL, l);
			minR = Math.min(minR, r);
		}
		
		int dif = minR - maxL;
		int ans = Math.max(dif + 1, 0);
		
		System.out.println(ans);
		

	}
}
