import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int M  = keyboard.nextInt();
		
		 int[] L = new int[M];
		 int[] R = new int[M];
		
		for(int i = 0; i < M ; i++) {
			L[i] = keyboard.nextInt();
			R[i] = keyboard.nextInt();
		}
		
		int min = L[0];
		int MAX = R[0];
		int ans = 0;
		
		for(int m = 0; m < M; m++) {
			
			if(min <= L[m]) {
				min = L[m];
			}
			if(MAX >= R[m]) {
				MAX = R[m];
			}
		}
		
		ans = MAX - min + 1;
		ans = Math.max(ans, 0);
		
		System.out.println(ans);
		keyboard.close();	
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int M  = keyboard.nextInt();
		
		 int[] L = new int[M];
		 int[] R = new int[M];
		
		for(int i = 0; i < M ; i++) {
			L[i] = keyboard.nextInt();
			R[i] = keyboard.nextInt();
		}
		
		int min = L[0];
		int MAX = R[0];
		int ans = 0;
		
		for(int m = 0; m < M; m++) {
			
			if(min <= L[m]) {
				min = L[m];
			}
			if(MAX >= R[m]) {
				MAX = R[m];
			}
		}
		
		ans = MAX - min + 1;
		ans = Math.max(ans, 0);
		
		System.out.println(ans);
		keyboard.close();	
	}
} Main public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int M  = keyboard.nextInt();
		
		 int[] L = new int[M];
		 int[] R = new int[M];
		
		for(int i = 0; i < M ; i++) {
			L[i] = keyboard.nextInt();
			R[i] = keyboard.nextInt();
		}
		
		int min = L[0];
		int MAX = R[0];
		int ans = 0;
		
		for(int m = 0; m < M; m++) {
			
			if(min <= L[m]) {
				min = L[m];
			}
			if(MAX >= R[m]) {
				MAX = R[m];
			}
		}
		
		ans = MAX - min + 1;
		ans = Math.max(ans, 0);
		
		System.out.println(ans);
		keyboard.close();	
	} main {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int M  = keyboard.nextInt();
		
		 int[] L = new int[M];
		 int[] R = new int[M];
		
		for(int i = 0; i < M ; i++) {
			L[i] = keyboard.nextInt();
			R[i] = keyboard.nextInt();
		}
		
		int min = L[0];
		int MAX = R[0];
		int ans = 0;
		
		for(int m = 0; m < M; m++) {
			
			if(min <= L[m]) {
				min = L[m];
			}
			if(MAX >= R[m]) {
				MAX = R[m];
			}
		}
		
		ans = MAX - min + 1;
		ans = Math.max(ans, 0);
		
		System.out.println(ans);
		keyboard.close();	
	} Scanner keyboard = new Scanner(System.in); keyboard new Scanner(System.in) int N  = keyboard.nextInt(); N keyboard.nextInt() keyboard.nextInt keyboard int M  = keyboard.nextInt(); M keyboard.nextInt() keyboard.nextInt keyboard 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] = keyboard.nextInt();
			R[i] = keyboard.nextInt();
		} int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
			L[i] = keyboard.nextInt();
			R[i] = keyboard.nextInt();
		} {
			L[i] = keyboard.nextInt();
			R[i] = keyboard.nextInt();
		} L[i] = keyboard.nextInt() L[i] L i keyboard.nextInt() keyboard.nextInt keyboard R[i] = keyboard.nextInt() R[i] R i keyboard.nextInt() keyboard.nextInt keyboard int min = L[0]; min L[0] L 0 int MAX = R[0]; MAX R[0] R 0 int ans = 0; ans 0 for(int m = 0; m < M; m++) {
			
			if(min <= L[m]) {
				min = L[m];
			}
			if(MAX >= R[m]) {
				MAX = R[m];
			}
		} int m = 0; int m = 0; m 0 m < M m M m++ m++ m {
			
			if(min <= L[m]) {
				min = L[m];
			}
			if(MAX >= R[m]) {
				MAX = R[m];
			}
		} {
			
			if(min <= L[m]) {
				min = L[m];
			}
			if(MAX >= R[m]) {
				MAX = R[m];
			}
		} if(min <= L[m]) {
				min = L[m];
			} min <= L[m] min L[m] L m {
				min = L[m];
			} min = L[m] min L[m] L m if(MAX >= R[m]) {
				MAX = R[m];
			} MAX >= R[m] MAX R[m] R m {
				MAX = R[m];
			} MAX = R[m] MAX R[m] R m ans = MAX - min + 1 ans MAX - min + 1 MAX - min MAX min 1 ans = Math.max(ans, 0) ans Math.max(ans, 0) Math.max Math ans 0 System.out.println(ans) System.out.println System.out System System.out ans keyboard.close() keyboard.close keyboard String[] args args public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int M  = keyboard.nextInt();
		
		 int[] L = new int[M];
		 int[] R = new int[M];
		
		for(int i = 0; i < M ; i++) {
			L[i] = keyboard.nextInt();
			R[i] = keyboard.nextInt();
		}
		
		int min = L[0];
		int MAX = R[0];
		int ans = 0;
		
		for(int m = 0; m < M; m++) {
			
			if(min <= L[m]) {
				min = L[m];
			}
			if(MAX >= R[m]) {
				MAX = R[m];
			}
		}
		
		ans = MAX - min + 1;
		ans = Math.max(ans, 0);
		
		System.out.println(ans);
		keyboard.close();	
	}
} public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int M  = keyboard.nextInt();
		
		 int[] L = new int[M];
		 int[] R = new int[M];
		
		for(int i = 0; i < M ; i++) {
			L[i] = keyboard.nextInt();
			R[i] = keyboard.nextInt();
		}
		
		int min = L[0];
		int MAX = R[0];
		int ans = 0;
		
		for(int m = 0; m < M; m++) {
			
			if(min <= L[m]) {
				min = L[m];
			}
			if(MAX >= R[m]) {
				MAX = R[m];
			}
		}
		
		ans = MAX - min + 1;
		ans = Math.max(ans, 0);
		
		System.out.println(ans);
		keyboard.close();	
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int M  = keyboard.nextInt();
		
		 int[] L = new int[M];
		 int[] R = new int[M];
		
		for(int i = 0; i < M ; i++) {
			L[i] = keyboard.nextInt();
			R[i] = keyboard.nextInt();
		}
		
		int min = L[0];
		int MAX = R[0];
		int ans = 0;
		
		for(int m = 0; m < M; m++) {
			
			if(min <= L[m]) {
				min = L[m];
			}
			if(MAX >= R[m]) {
				MAX = R[m];
			}
		}
		
		ans = MAX - min + 1;
		ans = Math.max(ans, 0);
		
		System.out.println(ans);
		keyboard.close();	
	}
}
