import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

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

		try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			String[] input = bf.readLine().split(" ");
			
			int n = Integer.parseInt(input[0]);
			int m = Integer.parseInt(input[1]);
			
			int l0=0;
			int r0=100000;
			String in;
			
			while( (in = bf.readLine()) != null ){
				if ( in.trim().length() ==  0 ) break;
				input = in.split(" ");
				int l = Integer.parseInt(input[0]);
				if (l>l0) l0=l;
				int r = Integer.parseInt(input[1]);
				if (r<r0) r0=r;
			}
			if(r0-l0+1<0){
				System.out.println(0);
			}else{
				System.out.println(r0-l0+1);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {

		try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			String[] input = bf.readLine().split(" ");
			
			int n = Integer.parseInt(input[0]);
			int m = Integer.parseInt(input[1]);
			
			int l0=0;
			int r0=100000;
			String in;
			
			while( (in = bf.readLine()) != null ){
				if ( in.trim().length() ==  0 ) break;
				input = in.split(" ");
				int l = Integer.parseInt(input[0]);
				if (l>l0) l0=l;
				int r = Integer.parseInt(input[1]);
				if (r<r0) r0=r;
			}
			if(r0-l0+1<0){
				System.out.println(0);
			}else{
				System.out.println(r0-l0+1);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
} Main public static void main(String[] args) {

		try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			String[] input = bf.readLine().split(" ");
			
			int n = Integer.parseInt(input[0]);
			int m = Integer.parseInt(input[1]);
			
			int l0=0;
			int r0=100000;
			String in;
			
			while( (in = bf.readLine()) != null ){
				if ( in.trim().length() ==  0 ) break;
				input = in.split(" ");
				int l = Integer.parseInt(input[0]);
				if (l>l0) l0=l;
				int r = Integer.parseInt(input[1]);
				if (r<r0) r0=r;
			}
			if(r0-l0+1<0){
				System.out.println(0);
			}else{
				System.out.println(r0-l0+1);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
	} main {

		try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			String[] input = bf.readLine().split(" ");
			
			int n = Integer.parseInt(input[0]);
			int m = Integer.parseInt(input[1]);
			
			int l0=0;
			int r0=100000;
			String in;
			
			while( (in = bf.readLine()) != null ){
				if ( in.trim().length() ==  0 ) break;
				input = in.split(" ");
				int l = Integer.parseInt(input[0]);
				if (l>l0) l0=l;
				int r = Integer.parseInt(input[1]);
				if (r<r0) r0=r;
			}
			if(r0-l0+1<0){
				System.out.println(0);
			}else{
				System.out.println(r0-l0+1);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
	} try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			String[] input = bf.readLine().split(" ");
			
			int n = Integer.parseInt(input[0]);
			int m = Integer.parseInt(input[1]);
			
			int l0=0;
			int r0=100000;
			String in;
			
			while( (in = bf.readLine()) != null ){
				if ( in.trim().length() ==  0 ) break;
				input = in.split(" ");
				int l = Integer.parseInt(input[0]);
				if (l>l0) l0=l;
				int r = Integer.parseInt(input[1]);
				if (r<r0) r0=r;
			}
			if(r0-l0+1<0){
				System.out.println(0);
			}else{
				System.out.println(r0-l0+1);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		} catch(Exception e){
			e.printStackTrace();
		} Exception e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			String[] input = bf.readLine().split(" ");
			
			int n = Integer.parseInt(input[0]);
			int m = Integer.parseInt(input[1]);
			
			int l0=0;
			int r0=100000;
			String in;
			
			while( (in = bf.readLine()) != null ){
				if ( in.trim().length() ==  0 ) break;
				input = in.split(" ");
				int l = Integer.parseInt(input[0]);
				if (l>l0) l0=l;
				int r = Integer.parseInt(input[1]);
				if (r<r0) r0=r;
			}
			if(r0-l0+1<0){
				System.out.println(0);
			}else{
				System.out.println(r0-l0+1);
			}
		} BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); bf new BufferedReader(new InputStreamReader(System.in)) String[] input = bf.readLine().split(" "); input bf.readLine().split(" ") bf.readLine().split bf.readLine() bf.readLine bf " " int n = Integer.parseInt(input[0]); n Integer.parseInt(input[0]) Integer.parseInt Integer input[0] input 0 int m = Integer.parseInt(input[1]); m Integer.parseInt(input[1]) Integer.parseInt Integer input[1] input 1 int l0=0; l0 0 int r0=100000; r0 100000 String in; in while( (in = bf.readLine()) != null ){
				if ( in.trim().length() ==  0 ) break;
				input = in.split(" ");
				int l = Integer.parseInt(input[0]);
				if (l>l0) l0=l;
				int r = Integer.parseInt(input[1]);
				if (r<r0) r0=r;
			} (in = bf.readLine()) != null (in = bf.readLine()) in bf.readLine() bf.readLine bf null {
				if ( in.trim().length() ==  0 ) break;
				input = in.split(" ");
				int l = Integer.parseInt(input[0]);
				if (l>l0) l0=l;
				int r = Integer.parseInt(input[1]);
				if (r<r0) r0=r;
			} if ( in.trim().length() ==  0 ) break; in.trim().length() ==  0 in.trim().length() in.trim().length in.trim() in.trim in 0 break; input = in.split(" ") input in.split(" ") in.split in " " int l = Integer.parseInt(input[0]); l Integer.parseInt(input[0]) Integer.parseInt Integer input[0] input 0 if (l>l0) l0=l; l>l0 l l0 l0=l l0 l int r = Integer.parseInt(input[1]); r Integer.parseInt(input[1]) Integer.parseInt Integer input[1] input 1 if (r<r0) r0=r; r<r0 r r0 r0=r r0 r if(r0-l0+1<0){
				System.out.println(0);
			}else{
				System.out.println(r0-l0+1);
			} r0-l0+1<0 r0-l0+1 r0-l0 r0 l0 1 0 {
				System.out.println(0);
			} System.out.println(0) System.out.println System.out System System.out 0 {
				System.out.println(r0-l0+1);
			} System.out.println(r0-l0+1) System.out.println System.out System System.out r0-l0+1 r0-l0 r0 l0 1 String[] args args public class Main {
	public static void main(String[] args) {

		try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			String[] input = bf.readLine().split(" ");
			
			int n = Integer.parseInt(input[0]);
			int m = Integer.parseInt(input[1]);
			
			int l0=0;
			int r0=100000;
			String in;
			
			while( (in = bf.readLine()) != null ){
				if ( in.trim().length() ==  0 ) break;
				input = in.split(" ");
				int l = Integer.parseInt(input[0]);
				if (l>l0) l0=l;
				int r = Integer.parseInt(input[1]);
				if (r<r0) r0=r;
			}
			if(r0-l0+1<0){
				System.out.println(0);
			}else{
				System.out.println(r0-l0+1);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
} public class Main {
	public static void main(String[] args) {

		try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			String[] input = bf.readLine().split(" ");
			
			int n = Integer.parseInt(input[0]);
			int m = Integer.parseInt(input[1]);
			
			int l0=0;
			int r0=100000;
			String in;
			
			while( (in = bf.readLine()) != null ){
				if ( in.trim().length() ==  0 ) break;
				input = in.split(" ");
				int l = Integer.parseInt(input[0]);
				if (l>l0) l0=l;
				int r = Integer.parseInt(input[1]);
				if (r<r0) r0=r;
			}
			if(r0-l0+1<0){
				System.out.println(0);
			}else{
				System.out.println(r0-l0+1);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

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

		try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			String[] input = bf.readLine().split(" ");
			
			int n = Integer.parseInt(input[0]);
			int m = Integer.parseInt(input[1]);
			
			int l0=0;
			int r0=100000;
			String in;
			
			while( (in = bf.readLine()) != null ){
				if ( in.trim().length() ==  0 ) break;
				input = in.split(" ");
				int l = Integer.parseInt(input[0]);
				if (l>l0) l0=l;
				int r = Integer.parseInt(input[1]);
				if (r<r0) r0=r;
			}
			if(r0-l0+1<0){
				System.out.println(0);
			}else{
				System.out.println(r0-l0+1);
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
}