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 = 1;
    int R = N;
    
    for(int i=0; i<M; i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      L = Math.max(L,a);
      R = Math.min(R,b);
    }
    
    if(R-L+1>0){
      System.out.println(R-L+1);
    } else {
      System.out.println(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 = 1;
    int R = N;
    
    for(int i=0; i<M; i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      L = Math.max(L,a);
      R = Math.min(R,b);
    }
    
    if(R-L+1>0){
      System.out.println(R-L+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 L = 1;
    int R = N;
    
    for(int i=0; i<M; i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      L = Math.max(L,a);
      R = Math.min(R,b);
    }
    
    if(R-L+1>0){
      System.out.println(R-L+1);
    } else {
      System.out.println(0);
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    int L = 1;
    int R = N;
    
    for(int i=0; i<M; i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      L = Math.max(L,a);
      R = Math.min(R,b);
    }
    
    if(R-L+1>0){
      System.out.println(R-L+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 L = 1; L 1 int R = N; R N for(int i=0; i<M; i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      L = Math.max(L,a);
      R = Math.min(R,b);
    } int i=0; int i=0; i 0 i<M i M i++ i++ i {
      int a = sc.nextInt();
      int b = sc.nextInt();
      L = Math.max(L,a);
      R = Math.min(R,b);
    } {
      int a = sc.nextInt();
      int b = sc.nextInt();
      L = Math.max(L,a);
      R = Math.min(R,b);
    } int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc L = Math.max(L,a) L Math.max(L,a) Math.max Math L a R = Math.min(R,b) R Math.min(R,b) Math.min Math R b if(R-L+1>0){
      System.out.println(R-L+1);
    } else {
      System.out.println(0);
    } R-L+1>0 R-L+1 R-L R L 1 0 {
      System.out.println(R-L+1);
    } System.out.println(R-L+1) System.out.println System.out System System.out R-L+1 R-L R L 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 L = 1;
    int R = N;
    
    for(int i=0; i<M; i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      L = Math.max(L,a);
      R = Math.min(R,b);
    }
    
    if(R-L+1>0){
      System.out.println(R-L+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 L = 1;
    int R = N;
    
    for(int i=0; i<M; i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      L = Math.max(L,a);
      R = Math.min(R,b);
    }
    
    if(R-L+1>0){
      System.out.println(R-L+1);
    } else {
      System.out.println(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 = 1;
    int R = N;
    
    for(int i=0; i<M; i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      L = Math.max(L,a);
      R = Math.min(R,b);
    }
    
    if(R-L+1>0){
      System.out.println(R-L+1);
    } else {
      System.out.println(0);
    }
  }
}
    
    