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 ans;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int maxL = 0;
		int minR = n;
		for(int i = 0; i < m; i++) {
			maxL = Math.max(maxL, sc.nextInt());
			minR = Math.min(minR, sc.nextInt());
		}
		ans = minR-maxL+1;
		System.out.println(Math.max(ans, 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 ans;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int maxL = 0;
		int minR = n;
		for(int i = 0; i < m; i++) {
			maxL = Math.max(maxL, sc.nextInt());
			minR = Math.min(minR, sc.nextInt());
		}
		ans = minR-maxL+1;
		System.out.println(Math.max(ans, 0));
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int ans;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int maxL = 0;
		int minR = n;
		for(int i = 0; i < m; i++) {
			maxL = Math.max(maxL, sc.nextInt());
			minR = Math.min(minR, sc.nextInt());
		}
		ans = minR-maxL+1;
		System.out.println(Math.max(ans, 0));
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int ans;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int maxL = 0;
		int minR = n;
		for(int i = 0; i < m; i++) {
			maxL = Math.max(maxL, sc.nextInt());
			minR = Math.min(minR, sc.nextInt());
		}
		ans = minR-maxL+1;
		System.out.println(Math.max(ans, 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 ans; ans int[] key = new int[n]; key new int[n] n for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		} int i = 1; int i = 1; i 1 i <=n i n i++ i++ i {
			key[i-1] = i;
		} {
			key[i-1] = i;
		} key[i-1] = i key[i-1] key i-1 i 1 i int maxL = 0; maxL 0 int minR = n; minR n for(int i = 0; i < m; i++) {
			maxL = Math.max(maxL, sc.nextInt());
			minR = Math.min(minR, sc.nextInt());
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			maxL = Math.max(maxL, sc.nextInt());
			minR = Math.min(minR, sc.nextInt());
		} {
			maxL = Math.max(maxL, sc.nextInt());
			minR = Math.min(minR, sc.nextInt());
		} maxL = Math.max(maxL, sc.nextInt()) maxL Math.max(maxL, sc.nextInt()) Math.max Math maxL sc.nextInt() sc.nextInt sc minR = Math.min(minR, sc.nextInt()) minR Math.min(minR, sc.nextInt()) Math.min Math minR sc.nextInt() sc.nextInt sc ans = minR-maxL+1 ans minR-maxL+1 minR-maxL minR maxL 1 System.out.println(Math.max(ans, 0)) System.out.println System.out System System.out Math.max(ans, 0) Math.max Math ans 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 ans;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int maxL = 0;
		int minR = n;
		for(int i = 0; i < m; i++) {
			maxL = Math.max(maxL, sc.nextInt());
			minR = Math.min(minR, sc.nextInt());
		}
		ans = minR-maxL+1;
		System.out.println(Math.max(ans, 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 ans;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int maxL = 0;
		int minR = n;
		for(int i = 0; i < m; i++) {
			maxL = Math.max(maxL, sc.nextInt());
			minR = Math.min(minR, sc.nextInt());
		}
		ans = minR-maxL+1;
		System.out.println(Math.max(ans, 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 ans;
		int[] key = new int[n];
		for(int i = 1; i <=n; i++) {
			key[i-1] = i;
		}
		int maxL = 0;
		int minR = n;
		for(int i = 0; i < m; i++) {
			maxL = Math.max(maxL, sc.nextInt());
			minR = Math.min(minR, sc.nextInt());
		}
		ans = minR-maxL+1;
		System.out.println(Math.max(ans, 0));
	}
}