import 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 L[] = new int[M]; 
    // int R[] = new int[M]; 
    int min = sc.nextInt();
    int max = sc.nextInt();
    for(int i = 1; i < M; i++){
      int tmp_min = sc.nextInt();
      int tmp_max = sc.nextInt();
      if(min<=tmp_min){
        min = tmp_min; 
      }
      if(tmp_max<=max){
        max = tmp_max; 
      }
    }
    System.out.println(Math.max((max-min+1),0));    
  
  }
}

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


