	import java.util.*;
public class Main {

		public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int N = sc.nextInt();
			// スペース区切りの整数の入力
			int M = sc.nextInt();
			int L =0;
			int R =0;
			int Lmax=0;
			int Rmin=N;
			for (int i = 0; i<M ; i++){
				L=sc.nextInt();
				R=sc.nextInt();
				if(Lmax<=L){
					Lmax = L;
				}
				if(Rmin>=R){
					Rmin = R;
				}
			}
			if(Rmin-Lmax>=0){
				System.out.println(Rmin-Lmax+1);
			}else{
				System.out.println(0);
			}
				
		}

	} import java.util.*; util.* java public class Main {

		public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int N = sc.nextInt();
			// スペース区切りの整数の入力
			int M = sc.nextInt();
			int L =0;
			int R =0;
			int Lmax=0;
			int Rmin=N;
			for (int i = 0; i<M ; i++){
				L=sc.nextInt();
				R=sc.nextInt();
				if(Lmax<=L){
					Lmax = L;
				}
				if(Rmin>=R){
					Rmin = R;
				}
			}
			if(Rmin-Lmax>=0){
				System.out.println(Rmin-Lmax+1);
			}else{
				System.out.println(0);
			}
				
		}

	} Main public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int N = sc.nextInt();
			// スペース区切りの整数の入力
			int M = sc.nextInt();
			int L =0;
			int R =0;
			int Lmax=0;
			int Rmin=N;
			for (int i = 0; i<M ; i++){
				L=sc.nextInt();
				R=sc.nextInt();
				if(Lmax<=L){
					Lmax = L;
				}
				if(Rmin>=R){
					Rmin = R;
				}
			}
			if(Rmin-Lmax>=0){
				System.out.println(Rmin-Lmax+1);
			}else{
				System.out.println(0);
			}
				
		} main {
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int N = sc.nextInt();
			// スペース区切りの整数の入力
			int M = sc.nextInt();
			int L =0;
			int R =0;
			int Lmax=0;
			int Rmin=N;
			for (int i = 0; i<M ; i++){
				L=sc.nextInt();
				R=sc.nextInt();
				if(Lmax<=L){
					Lmax = L;
				}
				if(Rmin>=R){
					Rmin = R;
				}
			}
			if(Rmin-Lmax>=0){
				System.out.println(Rmin-Lmax+1);
			}else{
				System.out.println(0);
			}
				
		} 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 L =0; L 0 int R =0; R 0 int Lmax=0; Lmax 0 int Rmin=N; Rmin N for (int i = 0; i<M ; i++){
				L=sc.nextInt();
				R=sc.nextInt();
				if(Lmax<=L){
					Lmax = L;
				}
				if(Rmin>=R){
					Rmin = R;
				}
			} int i = 0; int i = 0; i 0 i<M i M i++ i++ i {
				L=sc.nextInt();
				R=sc.nextInt();
				if(Lmax<=L){
					Lmax = L;
				}
				if(Rmin>=R){
					Rmin = R;
				}
			} {
				L=sc.nextInt();
				R=sc.nextInt();
				if(Lmax<=L){
					Lmax = L;
				}
				if(Rmin>=R){
					Rmin = R;
				}
			} L=sc.nextInt() L sc.nextInt() sc.nextInt sc R=sc.nextInt() R sc.nextInt() sc.nextInt sc if(Lmax<=L){
					Lmax = L;
				} Lmax<=L Lmax L {
					Lmax = L;
				} Lmax = L Lmax L if(Rmin>=R){
					Rmin = R;
				} Rmin>=R Rmin R {
					Rmin = R;
				} Rmin = R Rmin R if(Rmin-Lmax>=0){
				System.out.println(Rmin-Lmax+1);
			}else{
				System.out.println(0);
			} Rmin-Lmax>=0 Rmin-Lmax Rmin Lmax 0 {
				System.out.println(Rmin-Lmax+1);
			} System.out.println(Rmin-Lmax+1) System.out.println System.out System System.out Rmin-Lmax+1 Rmin-Lmax Rmin Lmax 1 {
				System.out.println(0);
			} System.out.println(0) System.out.println System.out System System.out 0 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 L =0;
			int R =0;
			int Lmax=0;
			int Rmin=N;
			for (int i = 0; i<M ; i++){
				L=sc.nextInt();
				R=sc.nextInt();
				if(Lmax<=L){
					Lmax = L;
				}
				if(Rmin>=R){
					Rmin = R;
				}
			}
			if(Rmin-Lmax>=0){
				System.out.println(Rmin-Lmax+1);
			}else{
				System.out.println(0);
			}
				
		}

	} public class Main {

		public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int N = sc.nextInt();
			// スペース区切りの整数の入力
			int M = sc.nextInt();
			int L =0;
			int R =0;
			int Lmax=0;
			int Rmin=N;
			for (int i = 0; i<M ; i++){
				L=sc.nextInt();
				R=sc.nextInt();
				if(Lmax<=L){
					Lmax = L;
				}
				if(Rmin>=R){
					Rmin = R;
				}
			}
			if(Rmin-Lmax>=0){
				System.out.println(Rmin-Lmax+1);
			}else{
				System.out.println(0);
			}
				
		}

	} Main
	import java.util.*;
public class Main {

		public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			// 整数の入力
			int N = sc.nextInt();
			// スペース区切りの整数の入力
			int M = sc.nextInt();
			int L =0;
			int R =0;
			int Lmax=0;
			int Rmin=N;
			for (int i = 0; i<M ; i++){
				L=sc.nextInt();
				R=sc.nextInt();
				if(Lmax<=L){
					Lmax = L;
				}
				if(Rmin>=R){
					Rmin = R;
				}
			}
			if(Rmin-Lmax>=0){
				System.out.println(Rmin-Lmax+1);
			}else{
				System.out.println(0);
			}
				
		}

	}