import 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 K[][] = new int[M][2];
		int min = Integer.MAX_VALUE;
		int max = 0;
		for(int i = 0; i < M; i++) {
			K[i][0] = sc.nextInt();
			max = Math.max(max, K[i][0]);
			K[i][1] = sc.nextInt();
			min = Math.min(min, K[i][1]);
		}
		System.out.println(Math.max(min - max + 1, 0));
	}
} import java.util.*; util.* java public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int K[][] = new int[M][2];
		int min = Integer.MAX_VALUE;
		int max = 0;
		for(int i = 0; i < M; i++) {
			K[i][0] = sc.nextInt();
			max = Math.max(max, K[i][0]);
			K[i][1] = sc.nextInt();
			min = Math.min(min, K[i][1]);
		}
		System.out.println(Math.max(min - max + 1, 0));
	}
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int K[][] = new int[M][2];
		int min = Integer.MAX_VALUE;
		int max = 0;
		for(int i = 0; i < M; i++) {
			K[i][0] = sc.nextInt();
			max = Math.max(max, K[i][0]);
			K[i][1] = sc.nextInt();
			min = Math.min(min, K[i][1]);
		}
		System.out.println(Math.max(min - max + 1, 0));
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int K[][] = new int[M][2];
		int min = Integer.MAX_VALUE;
		int max = 0;
		for(int i = 0; i < M; i++) {
			K[i][0] = sc.nextInt();
			max = Math.max(max, K[i][0]);
			K[i][1] = sc.nextInt();
			min = Math.min(min, K[i][1]);
		}
		System.out.println(Math.max(min - max + 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 K[][] = new int[M][2]; K new int[M][2] M 2 int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE int max = 0; max 0 for(int i = 0; i < M; i++) {
			K[i][0] = sc.nextInt();
			max = Math.max(max, K[i][0]);
			K[i][1] = sc.nextInt();
			min = Math.min(min, K[i][1]);
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			K[i][0] = sc.nextInt();
			max = Math.max(max, K[i][0]);
			K[i][1] = sc.nextInt();
			min = Math.min(min, K[i][1]);
		} {
			K[i][0] = sc.nextInt();
			max = Math.max(max, K[i][0]);
			K[i][1] = sc.nextInt();
			min = Math.min(min, K[i][1]);
		} K[i][0] = sc.nextInt() K[i][0] K[i] K i 0 sc.nextInt() sc.nextInt sc max = Math.max(max, K[i][0]) max Math.max(max, K[i][0]) Math.max Math max K[i][0] K[i] K i 0 K[i][1] = sc.nextInt() K[i][1] K[i] K i 1 sc.nextInt() sc.nextInt sc min = Math.min(min, K[i][1]) min Math.min(min, K[i][1]) Math.min Math min K[i][1] K[i] K i 1 System.out.println(Math.max(min - max + 1, 0)) System.out.println System.out System System.out Math.max(min - max + 1, 0) Math.max Math min - max + 1 min - max min max 1 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 K[][] = new int[M][2];
		int min = Integer.MAX_VALUE;
		int max = 0;
		for(int i = 0; i < M; i++) {
			K[i][0] = sc.nextInt();
			max = Math.max(max, K[i][0]);
			K[i][1] = sc.nextInt();
			min = Math.min(min, K[i][1]);
		}
		System.out.println(Math.max(min - max + 1, 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 K[][] = new int[M][2];
		int min = Integer.MAX_VALUE;
		int max = 0;
		for(int i = 0; i < M; i++) {
			K[i][0] = sc.nextInt();
			max = Math.max(max, K[i][0]);
			K[i][1] = sc.nextInt();
			min = Math.min(min, K[i][1]);
		}
		System.out.println(Math.max(min - max + 1, 0));
	}
} Main
import 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 K[][] = new int[M][2];
		int min = Integer.MAX_VALUE;
		int max = 0;
		for(int i = 0; i < M; i++) {
			K[i][0] = sc.nextInt();
			max = Math.max(max, K[i][0]);
			K[i][1] = sc.nextInt();
			min = Math.min(min, K[i][1]);
		}
		System.out.println(Math.max(min - max + 1, 0));
	}
}
