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 []l = new int [m];
		int []r = new int [m];
		int maxL = 0;
		int minR = 100000;
		for(int i = 0; i < m ; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
			
		}
		if(minR >= maxL) {
		System.out.println((minR - maxL + 1));
		}
		if(minR < maxL) {
	    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 []l = new int [m];
		int []r = new int [m];
		int maxL = 0;
		int minR = 100000;
		for(int i = 0; i < m ; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
			
		}
		if(minR >= maxL) {
		System.out.println((minR - maxL + 1));
		}
		if(minR < maxL) {
	    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 []l = new int [m];
		int []r = new int [m];
		int maxL = 0;
		int minR = 100000;
		for(int i = 0; i < m ; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
			
		}
		if(minR >= maxL) {
		System.out.println((minR - maxL + 1));
		}
		if(minR < maxL) {
	    System.out.println(0);
		}
		

	} 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];
		int maxL = 0;
		int minR = 100000;
		for(int i = 0; i < m ; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
			
		}
		if(minR >= maxL) {
		System.out.println((minR - maxL + 1));
		}
		if(minR < maxL) {
	    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 []l = new int [m]; l new int [m] m int []r = new int [m]; r new int [m] m int maxL = 0; maxL 0 int minR = 100000; minR 100000 for(int i = 0; i < m ; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
			
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
			
		} {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
			
		} 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 maxL = Math.max(maxL, l[i]) maxL Math.max(maxL, l[i]) Math.max Math maxL l[i] l i minR = Math.min(minR, r[i]) minR Math.min(minR, r[i]) Math.min Math minR r[i] r i if(minR >= maxL) {
		System.out.println((minR - maxL + 1));
		} minR >= maxL minR maxL {
		System.out.println((minR - maxL + 1));
		} System.out.println((minR - maxL + 1)) System.out.println System.out System System.out (minR - maxL + 1) minR - maxL minR maxL 1 if(minR < maxL) {
	    System.out.println(0);
		} minR < maxL minR maxL {
	    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 []l = new int [m];
		int []r = new int [m];
		int maxL = 0;
		int minR = 100000;
		for(int i = 0; i < m ; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
			
		}
		if(minR >= maxL) {
		System.out.println((minR - maxL + 1));
		}
		if(minR < maxL) {
	    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 []l = new int [m];
		int []r = new int [m];
		int maxL = 0;
		int minR = 100000;
		for(int i = 0; i < m ; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
			
		}
		if(minR >= maxL) {
		System.out.println((minR - maxL + 1));
		}
		if(minR < maxL) {
	    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 []l = new int [m];
		int []r = new int [m];
		int maxL = 0;
		int minR = 100000;
		for(int i = 0; i < m ; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
			maxL = Math.max(maxL, l[i]);
			minR = Math.min(minR, r[i]);
			
		}
		if(minR >= maxL) {
		System.out.println((minR - maxL + 1));
		}
		if(minR < maxL) {
	    System.out.println(0);
		}
		

	}

}
