import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int min =1;
		int max =100000;
		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			if(L>min) {
				min = L;
			}
			if(R<max) {
				max = R;
			}
		}
		if(max>=min) {
			System.out.println(max-min+1);
		} else {
			System.out.println("0");
		}
	}
} import java.io.FileNotFoundException; FileNotFoundException java.io import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int min =1;
		int max =100000;
		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			if(L>min) {
				min = L;
			}
			if(R<max) {
				max = R;
			}
		}
		if(max>=min) {
			System.out.println(max-min+1);
		} else {
			System.out.println("0");
		}
	}
} Main public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int min =1;
		int max =100000;
		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			if(L>min) {
				min = L;
			}
			if(R<max) {
				max = R;
			}
		}
		if(max>=min) {
			System.out.println(max-min+1);
		} else {
			System.out.println("0");
		}
	} main {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int min =1;
		int max =100000;
		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			if(L>min) {
				min = L;
			}
			if(R<max) {
				max = R;
			}
		}
		if(max>=min) {
			System.out.println(max-min+1);
		} else {
			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 min =1; min 1 int max =100000; max 100000 for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			if(L>min) {
				min = L;
			}
			if(R<max) {
				max = R;
			}
		} int i=0; int i=0; i 0 i<M i M i++ i++ i {
			int L = sc.nextInt();
			int R = sc.nextInt();
			if(L>min) {
				min = L;
			}
			if(R<max) {
				max = R;
			}
		} {
			int L = sc.nextInt();
			int R = sc.nextInt();
			if(L>min) {
				min = L;
			}
			if(R<max) {
				max = R;
			}
		} int L = sc.nextInt(); L sc.nextInt() sc.nextInt sc int R = sc.nextInt(); R sc.nextInt() sc.nextInt sc if(L>min) {
				min = L;
			} L>min L min {
				min = L;
			} min = L min L if(R<max) {
				max = R;
			} R<max R max {
				max = R;
			} max = R max R if(max>=min) {
			System.out.println(max-min+1);
		} else {
			System.out.println("0");
		} max>=min max min {
			System.out.println(max-min+1);
		} System.out.println(max-min+1) System.out.println System.out System System.out max-min+1 max-min max min 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) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int min =1;
		int max =100000;
		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			if(L>min) {
				min = L;
			}
			if(R<max) {
				max = R;
			}
		}
		if(max>=min) {
			System.out.println(max-min+1);
		} else {
			System.out.println("0");
		}
	}
} public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int min =1;
		int max =100000;
		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			if(L>min) {
				min = L;
			}
			if(R<max) {
				max = R;
			}
		}
		if(max>=min) {
			System.out.println(max-min+1);
		} else {
			System.out.println("0");
		}
	}
} Main
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int min =1;
		int max =100000;
		for(int i=0;i<M;i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			if(L>min) {
				min = L;
			}
			if(R<max) {
				max = R;
			}
		}
		if(max>=min) {
			System.out.println(max-min+1);
		} else {
			System.out.println("0");
		}
	}
}