import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int M = scan.nextInt();
			int[]L = new int[M];
			int[]R = new int[M];
			
			for(int i = 0;i<M;i++) {
				L[i] = scan.nextInt();
				R[i] = scan.nextInt();
			}
			
			int left = 1;
			int right = N;
			
			for(int i =0;i<M;i++) {
				if(left<L[i]) {
					left = L[i];
				}
				
				if(right>R[i]) {
					right = R[i];
				}
				
				
			}
			
			
			System.out.println(right-left>=0?right-left+1:0);
			
			
			
			
		}
		
		
	}
		

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int M = scan.nextInt();
			int[]L = new int[M];
			int[]R = new int[M];
			
			for(int i = 0;i<M;i++) {
				L[i] = scan.nextInt();
				R[i] = scan.nextInt();
			}
			
			int left = 1;
			int right = N;
			
			for(int i =0;i<M;i++) {
				if(left<L[i]) {
					left = L[i];
				}
				
				if(right>R[i]) {
					right = R[i];
				}
				
				
			}
			
			
			System.out.println(right-left>=0?right-left+1:0);
			
			
			
			
		}
		
		
	}
		

} Main public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int M = scan.nextInt();
			int[]L = new int[M];
			int[]R = new int[M];
			
			for(int i = 0;i<M;i++) {
				L[i] = scan.nextInt();
				R[i] = scan.nextInt();
			}
			
			int left = 1;
			int right = N;
			
			for(int i =0;i<M;i++) {
				if(left<L[i]) {
					left = L[i];
				}
				
				if(right>R[i]) {
					right = R[i];
				}
				
				
			}
			
			
			System.out.println(right-left>=0?right-left+1:0);
			
			
			
			
		}
		
		
	} main {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int M = scan.nextInt();
			int[]L = new int[M];
			int[]R = new int[M];
			
			for(int i = 0;i<M;i++) {
				L[i] = scan.nextInt();
				R[i] = scan.nextInt();
			}
			
			int left = 1;
			int right = N;
			
			for(int i =0;i<M;i++) {
				if(left<L[i]) {
					left = L[i];
				}
				
				if(right>R[i]) {
					right = R[i];
				}
				
				
			}
			
			
			System.out.println(right-left>=0?right-left+1:0);
			
			
			
			
		}
		
		
	} try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int M = scan.nextInt();
			int[]L = new int[M];
			int[]R = new int[M];
			
			for(int i = 0;i<M;i++) {
				L[i] = scan.nextInt();
				R[i] = scan.nextInt();
			}
			
			int left = 1;
			int right = N;
			
			for(int i =0;i<M;i++) {
				if(left<L[i]) {
					left = L[i];
				}
				
				if(right>R[i]) {
					right = R[i];
				}
				
				
			}
			
			
			System.out.println(right-left>=0?right-left+1:0);
			
			
			
			
		} {
			
			int N = scan.nextInt();
			int M = scan.nextInt();
			int[]L = new int[M];
			int[]R = new int[M];
			
			for(int i = 0;i<M;i++) {
				L[i] = scan.nextInt();
				R[i] = scan.nextInt();
			}
			
			int left = 1;
			int right = N;
			
			for(int i =0;i<M;i++) {
				if(left<L[i]) {
					left = L[i];
				}
				
				if(right>R[i]) {
					right = R[i];
				}
				
				
			}
			
			
			System.out.println(right-left>=0?right-left+1:0);
			
			
			
			
		} Scanner scan = new Scanner(System.in) Scanner scan = new Scanner(System.in) new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int M = scan.nextInt(); M scan.nextInt() scan.nextInt scan 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] = scan.nextInt();
				R[i] = scan.nextInt();
			} int i = 0; int i = 0; i 0 i<M i M i++ i++ i {
				L[i] = scan.nextInt();
				R[i] = scan.nextInt();
			} {
				L[i] = scan.nextInt();
				R[i] = scan.nextInt();
			} L[i] = scan.nextInt() L[i] L i scan.nextInt() scan.nextInt scan R[i] = scan.nextInt() R[i] R i scan.nextInt() scan.nextInt scan int left = 1; left 1 int right = N; right N for(int i =0;i<M;i++) {
				if(left<L[i]) {
					left = L[i];
				}
				
				if(right>R[i]) {
					right = R[i];
				}
				
				
			} int i =0; int i =0; i 0 i<M i M i++ i++ i {
				if(left<L[i]) {
					left = L[i];
				}
				
				if(right>R[i]) {
					right = R[i];
				}
				
				
			} {
				if(left<L[i]) {
					left = L[i];
				}
				
				if(right>R[i]) {
					right = R[i];
				}
				
				
			} if(left<L[i]) {
					left = L[i];
				} left<L[i] left L[i] L i {
					left = L[i];
				} left = L[i] left L[i] L i if(right>R[i]) {
					right = R[i];
				} right>R[i] right R[i] R i {
					right = R[i];
				} right = R[i] right R[i] R i System.out.println(right-left>=0?right-left+1:0) System.out.println System.out System System.out right-left>=0?right-left+1:0 right-left>=0 right-left right left 0 right-left+1 right-left right left 1 0 String[]args args public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int M = scan.nextInt();
			int[]L = new int[M];
			int[]R = new int[M];
			
			for(int i = 0;i<M;i++) {
				L[i] = scan.nextInt();
				R[i] = scan.nextInt();
			}
			
			int left = 1;
			int right = N;
			
			for(int i =0;i<M;i++) {
				if(left<L[i]) {
					left = L[i];
				}
				
				if(right>R[i]) {
					right = R[i];
				}
				
				
			}
			
			
			System.out.println(right-left>=0?right-left+1:0);
			
			
			
			
		}
		
		
	}
		

} public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int M = scan.nextInt();
			int[]L = new int[M];
			int[]R = new int[M];
			
			for(int i = 0;i<M;i++) {
				L[i] = scan.nextInt();
				R[i] = scan.nextInt();
			}
			
			int left = 1;
			int right = N;
			
			for(int i =0;i<M;i++) {
				if(left<L[i]) {
					left = L[i];
				}
				
				if(right>R[i]) {
					right = R[i];
				}
				
				
			}
			
			
			System.out.println(right-left>=0?right-left+1:0);
			
			
			
			
		}
		
		
	}
		

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int M = scan.nextInt();
			int[]L = new int[M];
			int[]R = new int[M];
			
			for(int i = 0;i<M;i++) {
				L[i] = scan.nextInt();
				R[i] = scan.nextInt();
			}
			
			int left = 1;
			int right = N;
			
			for(int i =0;i<M;i++) {
				if(left<L[i]) {
					left = L[i];
				}
				
				if(right>R[i]) {
					right = R[i];
				}
				
				
			}
			
			
			System.out.println(right-left>=0?right-left+1:0);
			
			
			
			
		}
		
		
	}
		

}
