import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();
		int M=sc.nextInt();

		int Start=sc.nextInt();
		int Last=sc.nextInt();

		boolean flag=false;

		for(int i=0;i<M-1;i++){
			int s=sc.nextInt();
			int l=sc.nextInt();

			if(Start>l){
				flag=true;
				continue;
			}
			if(Last<s){
				flag=true;
				continue;
			}

			if(s>Start && Last>=s) Start=s;
			if(Last>l && Start<=l) Last=l;

		}

		if(flag) System.out.println("0");
		else System.out.println((Last-Start)+1);

		sc.close();
	}

} import java.util.Scanner; Scanner 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 Start=sc.nextInt();
		int Last=sc.nextInt();

		boolean flag=false;

		for(int i=0;i<M-1;i++){
			int s=sc.nextInt();
			int l=sc.nextInt();

			if(Start>l){
				flag=true;
				continue;
			}
			if(Last<s){
				flag=true;
				continue;
			}

			if(s>Start && Last>=s) Start=s;
			if(Last>l && Start<=l) Last=l;

		}

		if(flag) System.out.println("0");
		else System.out.println((Last-Start)+1);

		sc.close();
	}

} Main public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();
		int M=sc.nextInt();

		int Start=sc.nextInt();
		int Last=sc.nextInt();

		boolean flag=false;

		for(int i=0;i<M-1;i++){
			int s=sc.nextInt();
			int l=sc.nextInt();

			if(Start>l){
				flag=true;
				continue;
			}
			if(Last<s){
				flag=true;
				continue;
			}

			if(s>Start && Last>=s) Start=s;
			if(Last>l && Start<=l) Last=l;

		}

		if(flag) System.out.println("0");
		else System.out.println((Last-Start)+1);

		sc.close();
	} main {

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();
		int M=sc.nextInt();

		int Start=sc.nextInt();
		int Last=sc.nextInt();

		boolean flag=false;

		for(int i=0;i<M-1;i++){
			int s=sc.nextInt();
			int l=sc.nextInt();

			if(Start>l){
				flag=true;
				continue;
			}
			if(Last<s){
				flag=true;
				continue;
			}

			if(s>Start && Last>=s) Start=s;
			if(Last>l && Start<=l) Last=l;

		}

		if(flag) System.out.println("0");
		else System.out.println((Last-Start)+1);

		sc.close();
	} 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 Start=sc.nextInt(); Start sc.nextInt() sc.nextInt sc int Last=sc.nextInt(); Last sc.nextInt() sc.nextInt sc boolean flag=false; flag false for(int i=0;i<M-1;i++){
			int s=sc.nextInt();
			int l=sc.nextInt();

			if(Start>l){
				flag=true;
				continue;
			}
			if(Last<s){
				flag=true;
				continue;
			}

			if(s>Start && Last>=s) Start=s;
			if(Last>l && Start<=l) Last=l;

		} int i=0; int i=0; i 0 i<M-1 i M-1 M 1 i++ i++ i {
			int s=sc.nextInt();
			int l=sc.nextInt();

			if(Start>l){
				flag=true;
				continue;
			}
			if(Last<s){
				flag=true;
				continue;
			}

			if(s>Start && Last>=s) Start=s;
			if(Last>l && Start<=l) Last=l;

		} {
			int s=sc.nextInt();
			int l=sc.nextInt();

			if(Start>l){
				flag=true;
				continue;
			}
			if(Last<s){
				flag=true;
				continue;
			}

			if(s>Start && Last>=s) Start=s;
			if(Last>l && Start<=l) Last=l;

		} int s=sc.nextInt(); s sc.nextInt() sc.nextInt sc int l=sc.nextInt(); l sc.nextInt() sc.nextInt sc if(Start>l){
				flag=true;
				continue;
			} Start>l Start l {
				flag=true;
				continue;
			} flag=true flag true continue; if(Last<s){
				flag=true;
				continue;
			} Last<s Last s {
				flag=true;
				continue;
			} flag=true flag true continue; if(s>Start && Last>=s) Start=s; s>Start && Last>=s s>Start s Start Last>=s Last s Start=s Start s if(Last>l && Start<=l) Last=l; Last>l && Start<=l Last>l Last l Start<=l Start l Last=l Last l if(flag) System.out.println("0");
		else System.out.println((Last-Start)+1); flag System.out.println("0") System.out.println System.out System System.out "0" System.out.println((Last-Start)+1) System.out.println System.out System System.out (Last-Start)+1 (Last-Start) Last Start 1 sc.close() sc.close sc 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 Start=sc.nextInt();
		int Last=sc.nextInt();

		boolean flag=false;

		for(int i=0;i<M-1;i++){
			int s=sc.nextInt();
			int l=sc.nextInt();

			if(Start>l){
				flag=true;
				continue;
			}
			if(Last<s){
				flag=true;
				continue;
			}

			if(s>Start && Last>=s) Start=s;
			if(Last>l && Start<=l) Last=l;

		}

		if(flag) System.out.println("0");
		else System.out.println((Last-Start)+1);

		sc.close();
	}

} public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();
		int M=sc.nextInt();

		int Start=sc.nextInt();
		int Last=sc.nextInt();

		boolean flag=false;

		for(int i=0;i<M-1;i++){
			int s=sc.nextInt();
			int l=sc.nextInt();

			if(Start>l){
				flag=true;
				continue;
			}
			if(Last<s){
				flag=true;
				continue;
			}

			if(s>Start && Last>=s) Start=s;
			if(Last>l && Start<=l) Last=l;

		}

		if(flag) System.out.println("0");
		else System.out.println((Last-Start)+1);

		sc.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();
		int M=sc.nextInt();

		int Start=sc.nextInt();
		int Last=sc.nextInt();

		boolean flag=false;

		for(int i=0;i<M-1;i++){
			int s=sc.nextInt();
			int l=sc.nextInt();

			if(Start>l){
				flag=true;
				continue;
			}
			if(Last<s){
				flag=true;
				continue;
			}

			if(s>Start && Last>=s) Start=s;
			if(Last>l && Start<=l) Last=l;

		}

		if(flag) System.out.println("0");
		else System.out.println((Last-Start)+1);

		sc.close();
	}

}
