import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		// 計算
		int maxL = 0;
		int minR = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++){
		    maxL = max(maxL, sc.nextInt());
		    minR = min(minR, sc.nextInt());
		}
		int result = max(0, minR - maxL + 1);

		// 出力
		System.out.println(result);
	}
} import java.util.*; util.* java import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; import java.math.BigInteger; BigInteger java.math public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		// 計算
		int maxL = 0;
		int minR = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++){
		    maxL = max(maxL, sc.nextInt());
		    minR = min(minR, sc.nextInt());
		}
		int result = max(0, minR - maxL + 1);

		// 出力
		System.out.println(result);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		// 計算
		int maxL = 0;
		int minR = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++){
		    maxL = max(maxL, sc.nextInt());
		    minR = min(minR, sc.nextInt());
		}
		int result = max(0, minR - maxL + 1);

		// 出力
		System.out.println(result);
	} main {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		// 計算
		int maxL = 0;
		int minR = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++){
		    maxL = max(maxL, sc.nextInt());
		    minR = min(minR, sc.nextInt());
		}
		int result = max(0, minR - maxL + 1);

		// 出力
		System.out.println(result);
	} 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 maxL = 0; maxL 0 int minR = Integer.MAX_VALUE; minR Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i = 0; i < m; i++){
		    maxL = max(maxL, sc.nextInt());
		    minR = min(minR, sc.nextInt());
		} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
		    maxL = max(maxL, sc.nextInt());
		    minR = min(minR, sc.nextInt());
		} {
		    maxL = max(maxL, sc.nextInt());
		    minR = min(minR, sc.nextInt());
		} maxL = max(maxL, sc.nextInt()) maxL max(maxL, sc.nextInt()) max maxL sc.nextInt() sc.nextInt sc minR = min(minR, sc.nextInt()) minR min(minR, sc.nextInt()) min minR sc.nextInt() sc.nextInt sc int result = max(0, minR - maxL + 1); result max(0, minR - maxL + 1) max 0 minR - maxL + 1 minR - maxL minR maxL 1 System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		// 計算
		int maxL = 0;
		int minR = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++){
		    maxL = max(maxL, sc.nextInt());
		    minR = min(minR, sc.nextInt());
		}
		int result = max(0, minR - maxL + 1);

		// 出力
		System.out.println(result);
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		// 計算
		int maxL = 0;
		int minR = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++){
		    maxL = max(maxL, sc.nextInt());
		    minR = min(minR, sc.nextInt());
		}
		int result = max(0, minR - maxL + 1);

		// 出力
		System.out.println(result);
	}
} Main
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		// 計算
		int maxL = 0;
		int minR = Integer.MAX_VALUE;
		for(int i = 0; i < m; i++){
		    maxL = max(maxL, sc.nextInt());
		    minR = min(minR, sc.nextInt());
		}
		int result = max(0, minR - maxL + 1);

		// 出力
		System.out.println(result);
	}
}