import java.util.Arrays;
import java.util.Scanner;
 
import javax.naming.spi.DirStateFactory.Result;
 
import org.omg.CORBA.PUBLIC_MEMBER;
 
public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static int[] first = splitInt(sc.nextLine(), " ");
	public static int[][] array2 = new int[2][first[1]];
	public static int[] array = new int[2];
	public static int result;
	
	public static void main(String[] args) {
		for(int i=0; i<first[1]; i++) {
			array = splitInt(sc.nextLine(), " ");
			array2[0][i] = array[0];
			array2[1][i] = array[1];
		}
		
		int min = 0;
		int max = first[0];
		
		for(int i=0; i<first[1]; i++) {
			if(min<array2[0][i]) {
				min = array2[0][i];
			}
			if(max>array2[1][i]) {
				max = array2[1][i];
			}
		}
		result = max-min+1;
		if(result<0) {
			System.out.println(0);
		}else {
			System.out.println(result);	
		}
		
	}
	public static String[] array4 = new String[2];
	public static int[] array5 = new int[2];
	public static int[] splitInt(String str, String split) {
		array4 = str.split(split);
		array5 = new int[array4.length];
	
		for(int i=0; i<array4.length; i++) {
				array5[i] = Integer.parseInt(array4[i]);
		}
		return array5;
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util import javax.naming.spi.DirStateFactory.Result; Result javax.naming.spi.DirStateFactory import org.omg.CORBA.PUBLIC_MEMBER; PUBLIC_MEMBER org.omg.CORBA public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static int[] first = splitInt(sc.nextLine(), " ");
	public static int[][] array2 = new int[2][first[1]];
	public static int[] array = new int[2];
	public static int result;
	
	public static void main(String[] args) {
		for(int i=0; i<first[1]; i++) {
			array = splitInt(sc.nextLine(), " ");
			array2[0][i] = array[0];
			array2[1][i] = array[1];
		}
		
		int min = 0;
		int max = first[0];
		
		for(int i=0; i<first[1]; i++) {
			if(min<array2[0][i]) {
				min = array2[0][i];
			}
			if(max>array2[1][i]) {
				max = array2[1][i];
			}
		}
		result = max-min+1;
		if(result<0) {
			System.out.println(0);
		}else {
			System.out.println(result);	
		}
		
	}
	public static String[] array4 = new String[2];
	public static int[] array5 = new int[2];
	public static int[] splitInt(String str, String split) {
		array4 = str.split(split);
		array5 = new int[array4.length];
	
		for(int i=0; i<array4.length; i++) {
				array5[i] = Integer.parseInt(array4[i]);
		}
		return array5;
	}
} Main public static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static int[] first = splitInt(sc.nextLine(), " "); first splitInt(sc.nextLine(), " ") splitInt sc.nextLine() sc.nextLine sc " " public static int[][] array2 = new int[2][first[1]]; array2 new int[2][first[1]] 2 first[1] first 1 public static int[] array = new int[2]; array new int[2] 2 public static int result; result public static String[] array4 = new String[2]; array4 new String[2] 2 public static int[] array5 = new int[2]; array5 new int[2] 2 public static void main(String[] args) {
		for(int i=0; i<first[1]; i++) {
			array = splitInt(sc.nextLine(), " ");
			array2[0][i] = array[0];
			array2[1][i] = array[1];
		}
		
		int min = 0;
		int max = first[0];
		
		for(int i=0; i<first[1]; i++) {
			if(min<array2[0][i]) {
				min = array2[0][i];
			}
			if(max>array2[1][i]) {
				max = array2[1][i];
			}
		}
		result = max-min+1;
		if(result<0) {
			System.out.println(0);
		}else {
			System.out.println(result);	
		}
		
	} main {
		for(int i=0; i<first[1]; i++) {
			array = splitInt(sc.nextLine(), " ");
			array2[0][i] = array[0];
			array2[1][i] = array[1];
		}
		
		int min = 0;
		int max = first[0];
		
		for(int i=0; i<first[1]; i++) {
			if(min<array2[0][i]) {
				min = array2[0][i];
			}
			if(max>array2[1][i]) {
				max = array2[1][i];
			}
		}
		result = max-min+1;
		if(result<0) {
			System.out.println(0);
		}else {
			System.out.println(result);	
		}
		
	} for(int i=0; i<first[1]; i++) {
			array = splitInt(sc.nextLine(), " ");
			array2[0][i] = array[0];
			array2[1][i] = array[1];
		} int i=0; int i=0; i 0 i<first[1] i first[1] first 1 i++ i++ i {
			array = splitInt(sc.nextLine(), " ");
			array2[0][i] = array[0];
			array2[1][i] = array[1];
		} {
			array = splitInt(sc.nextLine(), " ");
			array2[0][i] = array[0];
			array2[1][i] = array[1];
		} array = splitInt(sc.nextLine(), " ") array splitInt(sc.nextLine(), " ") splitInt sc.nextLine() sc.nextLine sc " " array2[0][i] = array[0] array2[0][i] array2[0] array2 0 i array[0] array 0 array2[1][i] = array[1] array2[1][i] array2[1] array2 1 i array[1] array 1 int min = 0; min 0 int max = first[0]; max first[0] first 0 for(int i=0; i<first[1]; i++) {
			if(min<array2[0][i]) {
				min = array2[0][i];
			}
			if(max>array2[1][i]) {
				max = array2[1][i];
			}
		} int i=0; int i=0; i 0 i<first[1] i first[1] first 1 i++ i++ i {
			if(min<array2[0][i]) {
				min = array2[0][i];
			}
			if(max>array2[1][i]) {
				max = array2[1][i];
			}
		} {
			if(min<array2[0][i]) {
				min = array2[0][i];
			}
			if(max>array2[1][i]) {
				max = array2[1][i];
			}
		} if(min<array2[0][i]) {
				min = array2[0][i];
			} min<array2[0][i] min array2[0][i] array2[0] array2 0 i {
				min = array2[0][i];
			} min = array2[0][i] min array2[0][i] array2[0] array2 0 i if(max>array2[1][i]) {
				max = array2[1][i];
			} max>array2[1][i] max array2[1][i] array2[1] array2 1 i {
				max = array2[1][i];
			} max = array2[1][i] max array2[1][i] array2[1] array2 1 i result = max-min+1 result max-min+1 max-min max min 1 if(result<0) {
			System.out.println(0);
		}else {
			System.out.println(result);	
		} result<0 result 0 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 {
			System.out.println(result);	
		} System.out.println(result) System.out.println System.out System System.out result String[] args args public static int[] splitInt(String str, String split) {
		array4 = str.split(split);
		array5 = new int[array4.length];
	
		for(int i=0; i<array4.length; i++) {
				array5[i] = Integer.parseInt(array4[i]);
		}
		return array5;
	} splitInt {
		array4 = str.split(split);
		array5 = new int[array4.length];
	
		for(int i=0; i<array4.length; i++) {
				array5[i] = Integer.parseInt(array4[i]);
		}
		return array5;
	} array4 = str.split(split) array4 str.split(split) str.split str split array5 = new int[array4.length] array5 new int[array4.length] array4.length array4 array4.length for(int i=0; i<array4.length; i++) {
				array5[i] = Integer.parseInt(array4[i]);
		} int i=0; int i=0; i 0 i<array4.length i array4.length array4 array4.length i++ i++ i {
				array5[i] = Integer.parseInt(array4[i]);
		} {
				array5[i] = Integer.parseInt(array4[i]);
		} array5[i] = Integer.parseInt(array4[i]) array5[i] array5 i Integer.parseInt(array4[i]) Integer.parseInt Integer array4[i] array4 i return array5; array5 String str str String split split public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static int[] first = splitInt(sc.nextLine(), " ");
	public static int[][] array2 = new int[2][first[1]];
	public static int[] array = new int[2];
	public static int result;
	
	public static void main(String[] args) {
		for(int i=0; i<first[1]; i++) {
			array = splitInt(sc.nextLine(), " ");
			array2[0][i] = array[0];
			array2[1][i] = array[1];
		}
		
		int min = 0;
		int max = first[0];
		
		for(int i=0; i<first[1]; i++) {
			if(min<array2[0][i]) {
				min = array2[0][i];
			}
			if(max>array2[1][i]) {
				max = array2[1][i];
			}
		}
		result = max-min+1;
		if(result<0) {
			System.out.println(0);
		}else {
			System.out.println(result);	
		}
		
	}
	public static String[] array4 = new String[2];
	public static int[] array5 = new int[2];
	public static int[] splitInt(String str, String split) {
		array4 = str.split(split);
		array5 = new int[array4.length];
	
		for(int i=0; i<array4.length; i++) {
				array5[i] = Integer.parseInt(array4[i]);
		}
		return array5;
	}
} public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static int[] first = splitInt(sc.nextLine(), " ");
	public static int[][] array2 = new int[2][first[1]];
	public static int[] array = new int[2];
	public static int result;
	
	public static void main(String[] args) {
		for(int i=0; i<first[1]; i++) {
			array = splitInt(sc.nextLine(), " ");
			array2[0][i] = array[0];
			array2[1][i] = array[1];
		}
		
		int min = 0;
		int max = first[0];
		
		for(int i=0; i<first[1]; i++) {
			if(min<array2[0][i]) {
				min = array2[0][i];
			}
			if(max>array2[1][i]) {
				max = array2[1][i];
			}
		}
		result = max-min+1;
		if(result<0) {
			System.out.println(0);
		}else {
			System.out.println(result);	
		}
		
	}
	public static String[] array4 = new String[2];
	public static int[] array5 = new int[2];
	public static int[] splitInt(String str, String split) {
		array4 = str.split(split);
		array5 = new int[array4.length];
	
		for(int i=0; i<array4.length; i++) {
				array5[i] = Integer.parseInt(array4[i]);
		}
		return array5;
	}
} Main
import java.util.Arrays;
import java.util.Scanner;
 
import javax.naming.spi.DirStateFactory.Result;
 
import org.omg.CORBA.PUBLIC_MEMBER;
 
public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static int[] first = splitInt(sc.nextLine(), " ");
	public static int[][] array2 = new int[2][first[1]];
	public static int[] array = new int[2];
	public static int result;
	
	public static void main(String[] args) {
		for(int i=0; i<first[1]; i++) {
			array = splitInt(sc.nextLine(), " ");
			array2[0][i] = array[0];
			array2[1][i] = array[1];
		}
		
		int min = 0;
		int max = first[0];
		
		for(int i=0; i<first[1]; i++) {
			if(min<array2[0][i]) {
				min = array2[0][i];
			}
			if(max>array2[1][i]) {
				max = array2[1][i];
			}
		}
		result = max-min+1;
		if(result<0) {
			System.out.println(0);
		}else {
			System.out.println(result);	
		}
		
	}
	public static String[] array4 = new String[2];
	public static int[] array5 = new int[2];
	public static int[] splitInt(String str, String split) {
		array4 = str.split(split);
		array5 = new int[array4.length];
	
		for(int i=0; i<array4.length; i++) {
				array5[i] = Integer.parseInt(array4[i]);
		}
		return array5;
	}
}
