import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int M = stdIn.nextInt();
		int L[] = new int[M];
		int R[] = new int[M];
		
		for(int i = 0; i < M; i++) {
			L[i] = stdIn.nextInt();
			R[i] = stdIn.nextInt();
		}
		int maxL = L[0];
		int minR = R[0];
		
		for(int i = 1; i < M; i++) {
			if(maxL < L[i]) {
				maxL = L[i];
			}
			if(minR > R[i]) {
				minR = R[i];
			}
		}
		
		if((minR - maxL) >= 0) {
			System.out.println(minR - maxL + 1);
		}
		else {
			System.out.println(0);
		}

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int M = stdIn.nextInt();
		int L[] = new int[M];
		int R[] = new int[M];
		
		for(int i = 0; i < M; i++) {
			L[i] = stdIn.nextInt();
			R[i] = stdIn.nextInt();
		}
		int maxL = L[0];
		int minR = R[0];
		
		for(int i = 1; i < M; i++) {
			if(maxL < L[i]) {
				maxL = L[i];
			}
			if(minR > R[i]) {
				minR = R[i];
			}
		}
		
		if((minR - maxL) >= 0) {
			System.out.println(minR - maxL + 1);
		}
		else {
			System.out.println(0);
		}

	}

} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int M = stdIn.nextInt();
		int L[] = new int[M];
		int R[] = new int[M];
		
		for(int i = 0; i < M; i++) {
			L[i] = stdIn.nextInt();
			R[i] = stdIn.nextInt();
		}
		int maxL = L[0];
		int minR = R[0];
		
		for(int i = 1; i < M; i++) {
			if(maxL < L[i]) {
				maxL = L[i];
			}
			if(minR > R[i]) {
				minR = R[i];
			}
		}
		
		if((minR - maxL) >= 0) {
			System.out.println(minR - maxL + 1);
		}
		else {
			System.out.println(0);
		}

	} main {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int M = stdIn.nextInt();
		int L[] = new int[M];
		int R[] = new int[M];
		
		for(int i = 0; i < M; i++) {
			L[i] = stdIn.nextInt();
			R[i] = stdIn.nextInt();
		}
		int maxL = L[0];
		int minR = R[0];
		
		for(int i = 1; i < M; i++) {
			if(maxL < L[i]) {
				maxL = L[i];
			}
			if(minR > R[i]) {
				minR = R[i];
			}
		}
		
		if((minR - maxL) >= 0) {
			System.out.println(minR - maxL + 1);
		}
		else {
			System.out.println(0);
		}

	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int N = stdIn.nextInt(); N stdIn.nextInt() stdIn.nextInt stdIn int M = stdIn.nextInt(); M stdIn.nextInt() stdIn.nextInt stdIn 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] = stdIn.nextInt();
			R[i] = stdIn.nextInt();
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			L[i] = stdIn.nextInt();
			R[i] = stdIn.nextInt();
		} {
			L[i] = stdIn.nextInt();
			R[i] = stdIn.nextInt();
		} L[i] = stdIn.nextInt() L[i] L i stdIn.nextInt() stdIn.nextInt stdIn R[i] = stdIn.nextInt() R[i] R i stdIn.nextInt() stdIn.nextInt stdIn int maxL = L[0]; maxL L[0] L 0 int minR = R[0]; minR R[0] R 0 for(int i = 1; i < M; i++) {
			if(maxL < L[i]) {
				maxL = L[i];
			}
			if(minR > R[i]) {
				minR = R[i];
			}
		} int i = 1; int i = 1; i 1 i < M i M i++ i++ i {
			if(maxL < L[i]) {
				maxL = L[i];
			}
			if(minR > R[i]) {
				minR = R[i];
			}
		} {
			if(maxL < L[i]) {
				maxL = L[i];
			}
			if(minR > R[i]) {
				minR = R[i];
			}
		} if(maxL < L[i]) {
				maxL = L[i];
			} maxL < L[i] maxL L[i] L i {
				maxL = L[i];
			} maxL = L[i] maxL L[i] L i if(minR > R[i]) {
				minR = R[i];
			} minR > R[i] minR R[i] R i {
				minR = R[i];
			} minR = R[i] minR R[i] R i if((minR - maxL) >= 0) {
			System.out.println(minR - maxL + 1);
		}
		else {
			System.out.println(0);
		} (minR - maxL) >= 0 (minR - maxL) minR maxL 0 {
			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 {
			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 stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int M = stdIn.nextInt();
		int L[] = new int[M];
		int R[] = new int[M];
		
		for(int i = 0; i < M; i++) {
			L[i] = stdIn.nextInt();
			R[i] = stdIn.nextInt();
		}
		int maxL = L[0];
		int minR = R[0];
		
		for(int i = 1; i < M; i++) {
			if(maxL < L[i]) {
				maxL = L[i];
			}
			if(minR > R[i]) {
				minR = R[i];
			}
		}
		
		if((minR - maxL) >= 0) {
			System.out.println(minR - maxL + 1);
		}
		else {
			System.out.println(0);
		}

	}

} public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int M = stdIn.nextInt();
		int L[] = new int[M];
		int R[] = new int[M];
		
		for(int i = 0; i < M; i++) {
			L[i] = stdIn.nextInt();
			R[i] = stdIn.nextInt();
		}
		int maxL = L[0];
		int minR = R[0];
		
		for(int i = 1; i < M; i++) {
			if(maxL < L[i]) {
				maxL = L[i];
			}
			if(minR > R[i]) {
				minR = R[i];
			}
		}
		
		if((minR - maxL) >= 0) {
			System.out.println(minR - maxL + 1);
		}
		else {
			System.out.println(0);
		}

	}

} Main
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int M = stdIn.nextInt();
		int L[] = new int[M];
		int R[] = new int[M];
		
		for(int i = 0; i < M; i++) {
			L[i] = stdIn.nextInt();
			R[i] = stdIn.nextInt();
		}
		int maxL = L[0];
		int minR = R[0];
		
		for(int i = 1; i < M; i++) {
			if(maxL < L[i]) {
				maxL = L[i];
			}
			if(minR > R[i]) {
				minR = R[i];
			}
		}
		
		if((minR - maxL) >= 0) {
			System.out.println(minR - maxL + 1);
		}
		else {
			System.out.println(0);
		}

	}

}