import java.util.*;
import java.lang.*;
import java.io.*;

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 = new int[m];
	int[] max = new int[m];
	int bottom = 1;
	int top = n;
	for(int i= 0; i < m; i++){
		min[i] = sc.nextInt();
		max[i] = sc.nextInt();
	}
	for(int i = 0; i < m; i++){
		if(min[i] > bottom) bottom = min[i];
		if(max[i] < top) top = max[i];
	}
	if(top >= bottom){
		System.out.println(top - bottom + 1);
	}else{
		System.out.println(0);
	}
}
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* 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[] min = new int[m];
	int[] max = new int[m];
	int bottom = 1;
	int top = n;
	for(int i= 0; i < m; i++){
		min[i] = sc.nextInt();
		max[i] = sc.nextInt();
	}
	for(int i = 0; i < m; i++){
		if(min[i] > bottom) bottom = min[i];
		if(max[i] < top) top = max[i];
	}
	if(top >= bottom){
		System.out.println(top - bottom + 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 = new int[m];
	int[] max = new int[m];
	int bottom = 1;
	int top = n;
	for(int i= 0; i < m; i++){
		min[i] = sc.nextInt();
		max[i] = sc.nextInt();
	}
	for(int i = 0; i < m; i++){
		if(min[i] > bottom) bottom = min[i];
		if(max[i] < top) top = max[i];
	}
	if(top >= bottom){
		System.out.println(top - bottom + 1);
	}else{
		System.out.println(0);
	}
} main {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int m = sc.nextInt();
	int[] min = new int[m];
	int[] max = new int[m];
	int bottom = 1;
	int top = n;
	for(int i= 0; i < m; i++){
		min[i] = sc.nextInt();
		max[i] = sc.nextInt();
	}
	for(int i = 0; i < m; i++){
		if(min[i] > bottom) bottom = min[i];
		if(max[i] < top) top = max[i];
	}
	if(top >= bottom){
		System.out.println(top - bottom + 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 = new int[m]; min new int[m] m int[] max = new int[m]; max new int[m] m int bottom = 1; bottom 1 int top = n; top n for(int i= 0; i < m; i++){
		min[i] = sc.nextInt();
		max[i] = sc.nextInt();
	} int i= 0; int i= 0; i 0 i < m i m i++ i++ i {
		min[i] = sc.nextInt();
		max[i] = sc.nextInt();
	} {
		min[i] = sc.nextInt();
		max[i] = sc.nextInt();
	} min[i] = sc.nextInt() min[i] min i sc.nextInt() sc.nextInt sc max[i] = sc.nextInt() max[i] max i sc.nextInt() sc.nextInt sc for(int i = 0; i < m; i++){
		if(min[i] > bottom) bottom = min[i];
		if(max[i] < top) top = max[i];
	} int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
		if(min[i] > bottom) bottom = min[i];
		if(max[i] < top) top = max[i];
	} {
		if(min[i] > bottom) bottom = min[i];
		if(max[i] < top) top = max[i];
	} if(min[i] > bottom) bottom = min[i]; min[i] > bottom min[i] min i bottom bottom = min[i] bottom min[i] min i if(max[i] < top) top = max[i]; max[i] < top max[i] max i top top = max[i] top max[i] max i if(top >= bottom){
		System.out.println(top - bottom + 1);
	}else{
		System.out.println(0);
	} top >= bottom top bottom {
		System.out.println(top - bottom + 1);
	} System.out.println(top - bottom + 1) System.out.println System.out System System.out top - bottom + 1 top - bottom top bottom 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 = new int[m];
	int[] max = new int[m];
	int bottom = 1;
	int top = n;
	for(int i= 0; i < m; i++){
		min[i] = sc.nextInt();
		max[i] = sc.nextInt();
	}
	for(int i = 0; i < m; i++){
		if(min[i] > bottom) bottom = min[i];
		if(max[i] < top) top = max[i];
	}
	if(top >= bottom){
		System.out.println(top - bottom + 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 = new int[m];
	int[] max = new int[m];
	int bottom = 1;
	int top = n;
	for(int i= 0; i < m; i++){
		min[i] = sc.nextInt();
		max[i] = sc.nextInt();
	}
	for(int i = 0; i < m; i++){
		if(min[i] > bottom) bottom = min[i];
		if(max[i] < top) top = max[i];
	}
	if(top >= bottom){
		System.out.println(top - bottom + 1);
	}else{
		System.out.println(0);
	}
}
} Main
import java.util.*;
import java.lang.*;
import java.io.*;

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 = new int[m];
	int[] max = new int[m];
	int bottom = 1;
	int top = n;
	for(int i= 0; i < m; i++){
		min[i] = sc.nextInt();
		max[i] = sc.nextInt();
	}
	for(int i = 0; i < m; i++){
		if(min[i] > bottom) bottom = min[i];
		if(max[i] < top) top = max[i];
	}
	if(top >= bottom){
		System.out.println(top - bottom + 1);
	}else{
		System.out.println(0);
	}
}
}
