import java.util.Scanner;

public class Main {
	long c[];
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min, max ;
		min =1;
		max =N;
		for (int i =0;i<M;i++) {
			int x,y;
			x= sc.nextInt();
			y =sc.nextInt();
			if (x>min) {
				min =x;
			}
			if (y<max) {
				max =y;
			}
		}
		if (max<min) {
			System.out.println(0);
			return ;
		}
		System.out.println(max-min+1);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	long c[];
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min, max ;
		min =1;
		max =N;
		for (int i =0;i<M;i++) {
			int x,y;
			x= sc.nextInt();
			y =sc.nextInt();
			if (x>min) {
				min =x;
			}
			if (y<max) {
				max =y;
			}
		}
		if (max<min) {
			System.out.println(0);
			return ;
		}
		System.out.println(max-min+1);
	}
} Main long c[]; c public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min, max ;
		min =1;
		max =N;
		for (int i =0;i<M;i++) {
			int x,y;
			x= sc.nextInt();
			y =sc.nextInt();
			if (x>min) {
				min =x;
			}
			if (y<max) {
				max =y;
			}
		}
		if (max<min) {
			System.out.println(0);
			return ;
		}
		System.out.println(max-min+1);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min, max ;
		min =1;
		max =N;
		for (int i =0;i<M;i++) {
			int x,y;
			x= sc.nextInt();
			y =sc.nextInt();
			if (x>min) {
				min =x;
			}
			if (y<max) {
				max =y;
			}
		}
		if (max<min) {
			System.out.println(0);
			return ;
		}
		System.out.println(max-min+1);
	} 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 min min max ; max min =1 min 1 max =N max N for (int i =0;i<M;i++) {
			int x,y;
			x= sc.nextInt();
			y =sc.nextInt();
			if (x>min) {
				min =x;
			}
			if (y<max) {
				max =y;
			}
		} int i =0; int i =0; i 0 i<M i M i++ i++ i {
			int x,y;
			x= sc.nextInt();
			y =sc.nextInt();
			if (x>min) {
				min =x;
			}
			if (y<max) {
				max =y;
			}
		} {
			int x,y;
			x= sc.nextInt();
			y =sc.nextInt();
			if (x>min) {
				min =x;
			}
			if (y<max) {
				max =y;
			}
		} int x x y; y x= sc.nextInt() x sc.nextInt() sc.nextInt sc y =sc.nextInt() y sc.nextInt() sc.nextInt sc if (x>min) {
				min =x;
			} x>min x min {
				min =x;
			} min =x min x if (y<max) {
				max =y;
			} y<max y max {
				max =y;
			} max =y max y if (max<min) {
			System.out.println(0);
			return ;
		} max<min max min {
			System.out.println(0);
			return ;
		} System.out.println(0) System.out.println System.out System System.out 0 return ; System.out.println(max-min+1) System.out.println System.out System System.out max-min+1 max-min max min 1 String[] args args public class Main {
	long c[];
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min, max ;
		min =1;
		max =N;
		for (int i =0;i<M;i++) {
			int x,y;
			x= sc.nextInt();
			y =sc.nextInt();
			if (x>min) {
				min =x;
			}
			if (y<max) {
				max =y;
			}
		}
		if (max<min) {
			System.out.println(0);
			return ;
		}
		System.out.println(max-min+1);
	}
} public class Main {
	long c[];
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min, max ;
		min =1;
		max =N;
		for (int i =0;i<M;i++) {
			int x,y;
			x= sc.nextInt();
			y =sc.nextInt();
			if (x>min) {
				min =x;
			}
			if (y<max) {
				max =y;
			}
		}
		if (max<min) {
			System.out.println(0);
			return ;
		}
		System.out.println(max-min+1);
	}
} Main
import java.util.Scanner;

public class Main {
	long c[];
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min, max ;
		min =1;
		max =N;
		for (int i =0;i<M;i++) {
			int x,y;
			x= sc.nextInt();
			y =sc.nextInt();
			if (x>min) {
				min =x;
			}
			if (y<max) {
				max =y;
			}
		}
		if (max<min) {
			System.out.println(0);
			return ;
		}
		System.out.println(max-min+1);
	}
}