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 min=0;
		int max=0;
		for(int i=0; i<m; i++) {
			if(i==0) {
				min= sc.nextInt();
				max = sc.nextInt();
			}else {
				int min0 = sc.nextInt();
				int max0 = sc.nextInt();
				if(min0 > min) {min = min0;}
				if(max0 < max) {max = max0;}
			}
		}
		if(max >= min) {
			System.out.println(max-min+1);
		}else {
			System.out.println(0);
		}
	}
} 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 min=0;
		int max=0;
		for(int i=0; i<m; i++) {
			if(i==0) {
				min= sc.nextInt();
				max = sc.nextInt();
			}else {
				int min0 = sc.nextInt();
				int max0 = sc.nextInt();
				if(min0 > min) {min = min0;}
				if(max0 < max) {max = max0;}
			}
		}
		if(max >= min) {
			System.out.println(max-min+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 min=0;
		int max=0;
		for(int i=0; i<m; i++) {
			if(i==0) {
				min= sc.nextInt();
				max = sc.nextInt();
			}else {
				int min0 = sc.nextInt();
				int max0 = sc.nextInt();
				if(min0 > min) {min = min0;}
				if(max0 < max) {max = max0;}
			}
		}
		if(max >= min) {
			System.out.println(max-min+1);
		}else {
			System.out.println(0);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int min=0;
		int max=0;
		for(int i=0; i<m; i++) {
			if(i==0) {
				min= sc.nextInt();
				max = sc.nextInt();
			}else {
				int min0 = sc.nextInt();
				int max0 = sc.nextInt();
				if(min0 > min) {min = min0;}
				if(max0 < max) {max = max0;}
			}
		}
		if(max >= min) {
			System.out.println(max-min+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 min=0; min 0 int max=0; max 0 for(int i=0; i<m; i++) {
			if(i==0) {
				min= sc.nextInt();
				max = sc.nextInt();
			}else {
				int min0 = sc.nextInt();
				int max0 = sc.nextInt();
				if(min0 > min) {min = min0;}
				if(max0 < max) {max = max0;}
			}
		} int i=0; int i=0; i 0 i<m i m i++ i++ i {
			if(i==0) {
				min= sc.nextInt();
				max = sc.nextInt();
			}else {
				int min0 = sc.nextInt();
				int max0 = sc.nextInt();
				if(min0 > min) {min = min0;}
				if(max0 < max) {max = max0;}
			}
		} {
			if(i==0) {
				min= sc.nextInt();
				max = sc.nextInt();
			}else {
				int min0 = sc.nextInt();
				int max0 = sc.nextInt();
				if(min0 > min) {min = min0;}
				if(max0 < max) {max = max0;}
			}
		} if(i==0) {
				min= sc.nextInt();
				max = sc.nextInt();
			}else {
				int min0 = sc.nextInt();
				int max0 = sc.nextInt();
				if(min0 > min) {min = min0;}
				if(max0 < max) {max = max0;}
			} i==0 i 0 {
				min= sc.nextInt();
				max = sc.nextInt();
			} min= sc.nextInt() min sc.nextInt() sc.nextInt sc max = sc.nextInt() max sc.nextInt() sc.nextInt sc {
				int min0 = sc.nextInt();
				int max0 = sc.nextInt();
				if(min0 > min) {min = min0;}
				if(max0 < max) {max = max0;}
			} int min0 = sc.nextInt(); min0 sc.nextInt() sc.nextInt sc int max0 = sc.nextInt(); max0 sc.nextInt() sc.nextInt sc if(min0 > min) {min = min0;} min0 > min min0 min {min = min0;} min = min0 min min0 if(max0 < max) {max = max0;} max0 < max max0 max {max = max0;} max = max0 max max0 if(max >= min) {
			System.out.println(max-min+1);
		}else {
			System.out.println(0);
		} max >= min max min {
			System.out.println(max-min+1);
		} System.out.println(max-min+1) System.out.println System.out System System.out max-min+1 max-min max min 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 min=0;
		int max=0;
		for(int i=0; i<m; i++) {
			if(i==0) {
				min= sc.nextInt();
				max = sc.nextInt();
			}else {
				int min0 = sc.nextInt();
				int max0 = sc.nextInt();
				if(min0 > min) {min = min0;}
				if(max0 < max) {max = max0;}
			}
		}
		if(max >= min) {
			System.out.println(max-min+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 min=0;
		int max=0;
		for(int i=0; i<m; i++) {
			if(i==0) {
				min= sc.nextInt();
				max = sc.nextInt();
			}else {
				int min0 = sc.nextInt();
				int max0 = sc.nextInt();
				if(min0 > min) {min = min0;}
				if(max0 < max) {max = max0;}
			}
		}
		if(max >= min) {
			System.out.println(max-min+1);
		}else {
			System.out.println(0);
		}
	}
} 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 min=0;
		int max=0;
		for(int i=0; i<m; i++) {
			if(i==0) {
				min= sc.nextInt();
				max = sc.nextInt();
			}else {
				int min0 = sc.nextInt();
				int max0 = sc.nextInt();
				if(min0 > min) {min = min0;}
				if(max0 < max) {max = max0;}
			}
		}
		if(max >= min) {
			System.out.println(max-min+1);
		}else {
			System.out.println(0);
		}
	}
}