import java.util.*;
public class Main {
	//定義関数から参照できる変数定義はこの辺
	static int N;
	static int M;
	static int Left_max=-1;
	static int Right_min=100001;

	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		for(int i=1;i<=M;i++){
			Left_max=Math.max(Left_max,sc.nextInt());
			Right_min=Math.min(Right_min,sc.nextInt());
		}


		if (Left_max<=Right_min) {
			System.out.println(Right_min-Left_max+1);
		}
		else{

			System.out.println(0);

		}

		//System.out.print(ans);
    }
} import java.util.*; util.* java public class Main {
	//定義関数から参照できる変数定義はこの辺
	static int N;
	static int M;
	static int Left_max=-1;
	static int Right_min=100001;

	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		for(int i=1;i<=M;i++){
			Left_max=Math.max(Left_max,sc.nextInt());
			Right_min=Math.min(Right_min,sc.nextInt());
		}


		if (Left_max<=Right_min) {
			System.out.println(Right_min-Left_max+1);
		}
		else{

			System.out.println(0);

		}

		//System.out.print(ans);
    }
} Main //定義関数から参照できる変数定義はこの辺
	static int N; N static int M; M static int Left_max=-1; Left_max -1 1 static int Right_min=100001; Right_min 100001 public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		for(int i=1;i<=M;i++){
			Left_max=Math.max(Left_max,sc.nextInt());
			Right_min=Math.min(Right_min,sc.nextInt());
		}


		if (Left_max<=Right_min) {
			System.out.println(Right_min-Left_max+1);
		}
		else{

			System.out.println(0);

		}

		//System.out.print(ans);
    } main {
    	Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		for(int i=1;i<=M;i++){
			Left_max=Math.max(Left_max,sc.nextInt());
			Right_min=Math.min(Right_min,sc.nextInt());
		}


		if (Left_max<=Right_min) {
			System.out.println(Right_min-Left_max+1);
		}
		else{

			System.out.println(0);

		}

		//System.out.print(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) N = sc.nextInt() N sc.nextInt() sc.nextInt sc M = sc.nextInt() M sc.nextInt() sc.nextInt sc for(int i=1;i<=M;i++){
			Left_max=Math.max(Left_max,sc.nextInt());
			Right_min=Math.min(Right_min,sc.nextInt());
		} int i=1; int i=1; i 1 i<=M i M i++ i++ i {
			Left_max=Math.max(Left_max,sc.nextInt());
			Right_min=Math.min(Right_min,sc.nextInt());
		} {
			Left_max=Math.max(Left_max,sc.nextInt());
			Right_min=Math.min(Right_min,sc.nextInt());
		} Left_max=Math.max(Left_max,sc.nextInt()) Left_max Math.max(Left_max,sc.nextInt()) Math.max Math Left_max sc.nextInt() sc.nextInt sc Right_min=Math.min(Right_min,sc.nextInt()) Right_min Math.min(Right_min,sc.nextInt()) Math.min Math Right_min sc.nextInt() sc.nextInt sc if (Left_max<=Right_min) {
			System.out.println(Right_min-Left_max+1);
		}
		else{

			System.out.println(0);

		} Left_max<=Right_min Left_max Right_min {
			System.out.println(Right_min-Left_max+1);
		} System.out.println(Right_min-Left_max+1) System.out.println System.out System System.out Right_min-Left_max+1 Right_min-Left_max Right_min Left_max 1 {

			System.out.println(0);

		} System.out.println(0) System.out.println System.out System System.out 0 String[] args args public class Main {
	//定義関数から参照できる変数定義はこの辺
	static int N;
	static int M;
	static int Left_max=-1;
	static int Right_min=100001;

	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		for(int i=1;i<=M;i++){
			Left_max=Math.max(Left_max,sc.nextInt());
			Right_min=Math.min(Right_min,sc.nextInt());
		}


		if (Left_max<=Right_min) {
			System.out.println(Right_min-Left_max+1);
		}
		else{

			System.out.println(0);

		}

		//System.out.print(ans);
    }
} public class Main {
	//定義関数から参照できる変数定義はこの辺
	static int N;
	static int M;
	static int Left_max=-1;
	static int Right_min=100001;

	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		for(int i=1;i<=M;i++){
			Left_max=Math.max(Left_max,sc.nextInt());
			Right_min=Math.min(Right_min,sc.nextInt());
		}


		if (Left_max<=Right_min) {
			System.out.println(Right_min-Left_max+1);
		}
		else{

			System.out.println(0);

		}

		//System.out.print(ans);
    }
} Main
import java.util.*;
public class Main {
	//定義関数から参照できる変数定義はこの辺
	static int N;
	static int M;
	static int Left_max=-1;
	static int Right_min=100001;

	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		M = sc.nextInt();
		for(int i=1;i<=M;i++){
			Left_max=Math.max(Left_max,sc.nextInt());
			Right_min=Math.min(Right_min,sc.nextInt());
		}


		if (Left_max<=Right_min) {
			System.out.println(Right_min-Left_max+1);
		}
		else{

			System.out.println(0);

		}

		//System.out.print(ans);
    }
}