import java.util.*;
import static java.lang.System.*;

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, max = 10000000, count = 0;
	  
	  for(int i=0; i<M; i++) {
		  int L = sc.nextInt();
		  int R = sc.nextInt();
		  if(min < L) min = L;
		  if(max > R)max = R;
	  }
	  for(int i=min; i<=max; i++) {
		  if(i <= N) count++;
	  }
	  out.println(count);
  	}
  }	   import java.util.*; util.* java import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; 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, max = 10000000, count = 0;
	  
	  for(int i=0; i<M; i++) {
		  int L = sc.nextInt();
		  int R = sc.nextInt();
		  if(min < L) min = L;
		  if(max > R)max = R;
	  }
	  for(int i=min; i<=max; i++) {
		  if(i <= N) count++;
	  }
	  out.println(count);
  	}
  } Main public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  
	  int N = sc.nextInt();
	  int M = sc.nextInt();
	  int min =0, max = 10000000, count = 0;
	  
	  for(int i=0; i<M; i++) {
		  int L = sc.nextInt();
		  int R = sc.nextInt();
		  if(min < L) min = L;
		  if(max > R)max = R;
	  }
	  for(int i=min; i<=max; i++) {
		  if(i <= N) count++;
	  }
	  out.println(count);
  	} main {
	  Scanner sc = new Scanner(System.in);
	  
	  int N = sc.nextInt();
	  int M = sc.nextInt();
	  int min =0, max = 10000000, count = 0;
	  
	  for(int i=0; i<M; i++) {
		  int L = sc.nextInt();
		  int R = sc.nextInt();
		  if(min < L) min = L;
		  if(max > R)max = R;
	  }
	  for(int i=min; i<=max; i++) {
		  if(i <= N) count++;
	  }
	  out.println(count);
  	} 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 max = 10000000 max 10000000 count = 0; count 0 for(int i=0; i<M; i++) {
		  int L = sc.nextInt();
		  int R = sc.nextInt();
		  if(min < L) min = L;
		  if(max > R)max = R;
	  } int i=0; int i=0; i 0 i<M i M i++ i++ i {
		  int L = sc.nextInt();
		  int R = sc.nextInt();
		  if(min < L) min = L;
		  if(max > R)max = R;
	  } {
		  int L = sc.nextInt();
		  int R = sc.nextInt();
		  if(min < L) min = L;
		  if(max > R)max = R;
	  } int L = sc.nextInt(); L sc.nextInt() sc.nextInt sc int R = sc.nextInt(); R sc.nextInt() sc.nextInt sc if(min < L) min = L; min < L min L min = L min L if(max > R)max = R; max > R max R max = R max R for(int i=min; i<=max; i++) {
		  if(i <= N) count++;
	  } int i=min; int i=min; i min i<=max i max i++ i++ i {
		  if(i <= N) count++;
	  } {
		  if(i <= N) count++;
	  } if(i <= N) count++; i <= N i N count++ count out.println(count) out.println out count 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, max = 10000000, count = 0;
	  
	  for(int i=0; i<M; i++) {
		  int L = sc.nextInt();
		  int R = sc.nextInt();
		  if(min < L) min = L;
		  if(max > R)max = R;
	  }
	  for(int i=min; i<=max; i++) {
		  if(i <= N) count++;
	  }
	  out.println(count);
  	}
  } 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, max = 10000000, count = 0;
	  
	  for(int i=0; i<M; i++) {
		  int L = sc.nextInt();
		  int R = sc.nextInt();
		  if(min < L) min = L;
		  if(max > R)max = R;
	  }
	  for(int i=min; i<=max; i++) {
		  if(i <= N) count++;
	  }
	  out.println(count);
  	}
  } Main
import java.util.*;
import static java.lang.System.*;

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, max = 10000000, count = 0;
	  
	  for(int i=0; i<M; i++) {
		  int L = sc.nextInt();
		  int R = sc.nextInt();
		  if(min < L) min = L;
		  if(max > R)max = R;
	  }
	  for(int i=min; i<=max; i++) {
		  if(i <= N) count++;
	  }
	  out.println(count);
  	}
  }	  