import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int m = seer.nextInt();
		int[] d = new int[n];
		int maxa = 0, minb = n+1;
		for(int i = 0; i < m; i++){
			int a = seer.nextInt();
			int b = seer.nextInt();
			maxa = Integer.max(maxa, a);
			minb = Integer.min(minb, b);
		}
		if(minb < maxa){
			System.out.println(0);
		}
		else{
			System.out.println(minb-maxa+1);
		}
	}
} import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int m = seer.nextInt();
		int[] d = new int[n];
		int maxa = 0, minb = n+1;
		for(int i = 0; i < m; i++){
			int a = seer.nextInt();
			int b = seer.nextInt();
			maxa = Integer.max(maxa, a);
			minb = Integer.min(minb, b);
		}
		if(minb < maxa){
			System.out.println(0);
		}
		else{
			System.out.println(minb-maxa+1);
		}
	}
} Main public static void main(String[] args) {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int m = seer.nextInt();
		int[] d = new int[n];
		int maxa = 0, minb = n+1;
		for(int i = 0; i < m; i++){
			int a = seer.nextInt();
			int b = seer.nextInt();
			maxa = Integer.max(maxa, a);
			minb = Integer.min(minb, b);
		}
		if(minb < maxa){
			System.out.println(0);
		}
		else{
			System.out.println(minb-maxa+1);
		}
	} main {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int m = seer.nextInt();
		int[] d = new int[n];
		int maxa = 0, minb = n+1;
		for(int i = 0; i < m; i++){
			int a = seer.nextInt();
			int b = seer.nextInt();
			maxa = Integer.max(maxa, a);
			minb = Integer.min(minb, b);
		}
		if(minb < maxa){
			System.out.println(0);
		}
		else{
			System.out.println(minb-maxa+1);
		}
	} Scanner seer = new Scanner(System.in); seer new Scanner(System.in) int n = seer.nextInt(); n seer.nextInt() seer.nextInt seer int m = seer.nextInt(); m seer.nextInt() seer.nextInt seer int[] d = new int[n]; d new int[n] n int maxa = 0 maxa 0 minb = n+1; minb n+1 n 1 for(int i = 0; i < m; i++){
			int a = seer.nextInt();
			int b = seer.nextInt();
			maxa = Integer.max(maxa, a);
			minb = Integer.min(minb, b);
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
			int a = seer.nextInt();
			int b = seer.nextInt();
			maxa = Integer.max(maxa, a);
			minb = Integer.min(minb, b);
		} {
			int a = seer.nextInt();
			int b = seer.nextInt();
			maxa = Integer.max(maxa, a);
			minb = Integer.min(minb, b);
		} int a = seer.nextInt(); a seer.nextInt() seer.nextInt seer int b = seer.nextInt(); b seer.nextInt() seer.nextInt seer maxa = Integer.max(maxa, a) maxa Integer.max(maxa, a) Integer.max Integer maxa a minb = Integer.min(minb, b) minb Integer.min(minb, b) Integer.min Integer minb b if(minb < maxa){
			System.out.println(0);
		}
		else{
			System.out.println(minb-maxa+1);
		} minb < maxa minb maxa {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(minb-maxa+1);
		} System.out.println(minb-maxa+1) System.out.println System.out System System.out minb-maxa+1 minb-maxa minb maxa 1 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int m = seer.nextInt();
		int[] d = new int[n];
		int maxa = 0, minb = n+1;
		for(int i = 0; i < m; i++){
			int a = seer.nextInt();
			int b = seer.nextInt();
			maxa = Integer.max(maxa, a);
			minb = Integer.min(minb, b);
		}
		if(minb < maxa){
			System.out.println(0);
		}
		else{
			System.out.println(minb-maxa+1);
		}
	}
} public class Main {

	public static void main(String[] args) {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int m = seer.nextInt();
		int[] d = new int[n];
		int maxa = 0, minb = n+1;
		for(int i = 0; i < m; i++){
			int a = seer.nextInt();
			int b = seer.nextInt();
			maxa = Integer.max(maxa, a);
			minb = Integer.min(minb, b);
		}
		if(minb < maxa){
			System.out.println(0);
		}
		else{
			System.out.println(minb-maxa+1);
		}
	}
} Main
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int m = seer.nextInt();
		int[] d = new int[n];
		int maxa = 0, minb = n+1;
		for(int i = 0; i < m; i++){
			int a = seer.nextInt();
			int b = seer.nextInt();
			maxa = Integer.max(maxa, a);
			minb = Integer.min(minb, b);
		}
		if(minb < maxa){
			System.out.println(0);
		}
		else{
			System.out.println(minb-maxa+1);
		}
	}
}
