
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int m=scn.nextInt();
		int [][]arr=new int[m][2];
		for(int i=0;i<m;i++) {
			arr[i][0]=scn.nextInt();
			arr[i][1]=scn.nextInt();
		}
		
		int left=arr[0][0],right=arr[0][1];
		for(int i=1;i<m;i++) {
			if(arr[i][1]<left||arr[i][0]>right) {
				System.out.println(0);
				return;
			}else {
					if(right<=arr[i][1]) {
						if(left<arr[i][0])
						left=arr[i][0];
					}else if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					}
			
			}
		}
		System.out.println(right-left+1);
	}

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int m=scn.nextInt();
		int [][]arr=new int[m][2];
		for(int i=0;i<m;i++) {
			arr[i][0]=scn.nextInt();
			arr[i][1]=scn.nextInt();
		}
		
		int left=arr[0][0],right=arr[0][1];
		for(int i=1;i<m;i++) {
			if(arr[i][1]<left||arr[i][0]>right) {
				System.out.println(0);
				return;
			}else {
					if(right<=arr[i][1]) {
						if(left<arr[i][0])
						left=arr[i][0];
					}else if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					}
			
			}
		}
		System.out.println(right-left+1);
	}

} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int m=scn.nextInt();
		int [][]arr=new int[m][2];
		for(int i=0;i<m;i++) {
			arr[i][0]=scn.nextInt();
			arr[i][1]=scn.nextInt();
		}
		
		int left=arr[0][0],right=arr[0][1];
		for(int i=1;i<m;i++) {
			if(arr[i][1]<left||arr[i][0]>right) {
				System.out.println(0);
				return;
			}else {
					if(right<=arr[i][1]) {
						if(left<arr[i][0])
						left=arr[i][0];
					}else if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					}
			
			}
		}
		System.out.println(right-left+1);
	} main {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int m=scn.nextInt();
		int [][]arr=new int[m][2];
		for(int i=0;i<m;i++) {
			arr[i][0]=scn.nextInt();
			arr[i][1]=scn.nextInt();
		}
		
		int left=arr[0][0],right=arr[0][1];
		for(int i=1;i<m;i++) {
			if(arr[i][1]<left||arr[i][0]>right) {
				System.out.println(0);
				return;
			}else {
					if(right<=arr[i][1]) {
						if(left<arr[i][0])
						left=arr[i][0];
					}else if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					}
			
			}
		}
		System.out.println(right-left+1);
	} Scanner scn=new Scanner(System.in); scn new Scanner(System.in) int n=scn.nextInt(); n scn.nextInt() scn.nextInt scn int m=scn.nextInt(); m scn.nextInt() scn.nextInt scn int [][]arr=new int[m][2]; arr new int[m][2] m 2 for(int i=0;i<m;i++) {
			arr[i][0]=scn.nextInt();
			arr[i][1]=scn.nextInt();
		} int i=0; int i=0; i 0 i<m i m i++ i++ i {
			arr[i][0]=scn.nextInt();
			arr[i][1]=scn.nextInt();
		} {
			arr[i][0]=scn.nextInt();
			arr[i][1]=scn.nextInt();
		} arr[i][0]=scn.nextInt() arr[i][0] arr[i] arr i 0 scn.nextInt() scn.nextInt scn arr[i][1]=scn.nextInt() arr[i][1] arr[i] arr i 1 scn.nextInt() scn.nextInt scn int left=arr[0][0] left arr[0][0] arr[0] arr 0 0 right=arr[0][1]; right arr[0][1] arr[0] arr 0 1 for(int i=1;i<m;i++) {
			if(arr[i][1]<left||arr[i][0]>right) {
				System.out.println(0);
				return;
			}else {
					if(right<=arr[i][1]) {
						if(left<arr[i][0])
						left=arr[i][0];
					}else if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					}
			
			}
		} int i=1; int i=1; i 1 i<m i m i++ i++ i {
			if(arr[i][1]<left||arr[i][0]>right) {
				System.out.println(0);
				return;
			}else {
					if(right<=arr[i][1]) {
						if(left<arr[i][0])
						left=arr[i][0];
					}else if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					}
			
			}
		} {
			if(arr[i][1]<left||arr[i][0]>right) {
				System.out.println(0);
				return;
			}else {
					if(right<=arr[i][1]) {
						if(left<arr[i][0])
						left=arr[i][0];
					}else if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					}
			
			}
		} if(arr[i][1]<left||arr[i][0]>right) {
				System.out.println(0);
				return;
			}else {
					if(right<=arr[i][1]) {
						if(left<arr[i][0])
						left=arr[i][0];
					}else if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					}
			
			} arr[i][1]<left||arr[i][0]>right arr[i][1]<left arr[i][1] arr[i] arr i 1 left arr[i][0]>right arr[i][0] arr[i] arr i 0 right {
				System.out.println(0);
				return;
			} System.out.println(0) System.out.println System.out System System.out 0 return; {
					if(right<=arr[i][1]) {
						if(left<arr[i][0])
						left=arr[i][0];
					}else if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					}
			
			} if(right<=arr[i][1]) {
						if(left<arr[i][0])
						left=arr[i][0];
					}else if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					} right<=arr[i][1] right arr[i][1] arr[i] arr i 1 {
						if(left<arr[i][0])
						left=arr[i][0];
					} if(left<arr[i][0])
						left=arr[i][0]; left<arr[i][0] left arr[i][0] arr[i] arr i 0 left=arr[i][0] left arr[i][0] arr[i] arr i 0 if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					} right>arr[i][1] right arr[i][1] arr[i] arr i 1 {
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					} right=arr[i][1] right arr[i][1] arr[i] arr i 1 if(arr[i][0]>left)
							left=arr[i][0]; arr[i][0]>left arr[i][0] arr[i] arr i 0 left left=arr[i][0] left arr[i][0] arr[i] arr i 0 System.out.println(right-left+1) System.out.println System.out System System.out right-left+1 right-left right left 1 String[] args args public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int m=scn.nextInt();
		int [][]arr=new int[m][2];
		for(int i=0;i<m;i++) {
			arr[i][0]=scn.nextInt();
			arr[i][1]=scn.nextInt();
		}
		
		int left=arr[0][0],right=arr[0][1];
		for(int i=1;i<m;i++) {
			if(arr[i][1]<left||arr[i][0]>right) {
				System.out.println(0);
				return;
			}else {
					if(right<=arr[i][1]) {
						if(left<arr[i][0])
						left=arr[i][0];
					}else if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					}
			
			}
		}
		System.out.println(right-left+1);
	}

} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int m=scn.nextInt();
		int [][]arr=new int[m][2];
		for(int i=0;i<m;i++) {
			arr[i][0]=scn.nextInt();
			arr[i][1]=scn.nextInt();
		}
		
		int left=arr[0][0],right=arr[0][1];
		for(int i=1;i<m;i++) {
			if(arr[i][1]<left||arr[i][0]>right) {
				System.out.println(0);
				return;
			}else {
					if(right<=arr[i][1]) {
						if(left<arr[i][0])
						left=arr[i][0];
					}else if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					}
			
			}
		}
		System.out.println(right-left+1);
	}

} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		int n=scn.nextInt();
		int m=scn.nextInt();
		int [][]arr=new int[m][2];
		for(int i=0;i<m;i++) {
			arr[i][0]=scn.nextInt();
			arr[i][1]=scn.nextInt();
		}
		
		int left=arr[0][0],right=arr[0][1];
		for(int i=1;i<m;i++) {
			if(arr[i][1]<left||arr[i][0]>right) {
				System.out.println(0);
				return;
			}else {
					if(right<=arr[i][1]) {
						if(left<arr[i][0])
						left=arr[i][0];
					}else if(right>arr[i][1]){
						right=arr[i][1];
						if(arr[i][0]>left)
							left=arr[i][0];
					}
			
			}
		}
		System.out.println(right-left+1);
	}

}
