import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int under = 0;
    int top = Integer.MAX_VALUE;
    for(int i=0; i<M; i++){
      under = Math.max(sc.nextInt(),under);
      top = Math.min(sc.nextInt(),top);
    }
    int diff = top - under;
    int ans =diff + 1;
    System.out.print(((ans<0)?0:ans));
  }
}
     import java.util.*; util.* java class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int under = 0;
    int top = Integer.MAX_VALUE;
    for(int i=0; i<M; i++){
      under = Math.max(sc.nextInt(),under);
      top = Math.min(sc.nextInt(),top);
    }
    int diff = top - under;
    int ans =diff + 1;
    System.out.print(((ans<0)?0:ans));
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int under = 0;
    int top = Integer.MAX_VALUE;
    for(int i=0; i<M; i++){
      under = Math.max(sc.nextInt(),under);
      top = Math.min(sc.nextInt(),top);
    }
    int diff = top - under;
    int ans =diff + 1;
    System.out.print(((ans<0)?0:ans));
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int under = 0;
    int top = Integer.MAX_VALUE;
    for(int i=0; i<M; i++){
      under = Math.max(sc.nextInt(),under);
      top = Math.min(sc.nextInt(),top);
    }
    int diff = top - under;
    int ans =diff + 1;
    System.out.print(((ans<0)?0:ans));
  } 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 under = 0; under 0 int top = Integer.MAX_VALUE; top Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i=0; i<M; i++){
      under = Math.max(sc.nextInt(),under);
      top = Math.min(sc.nextInt(),top);
    } int i=0; int i=0; i 0 i<M i M i++ i++ i {
      under = Math.max(sc.nextInt(),under);
      top = Math.min(sc.nextInt(),top);
    } {
      under = Math.max(sc.nextInt(),under);
      top = Math.min(sc.nextInt(),top);
    } under = Math.max(sc.nextInt(),under) under Math.max(sc.nextInt(),under) Math.max Math sc.nextInt() sc.nextInt sc under top = Math.min(sc.nextInt(),top) top Math.min(sc.nextInt(),top) Math.min Math sc.nextInt() sc.nextInt sc top int diff = top - under; diff top - under top under int ans =diff + 1; ans diff + 1 diff 1 System.out.print(((ans<0)?0:ans)) System.out.print System.out System System.out ((ans<0)?0:ans) (ans<0) ans 0 0 ans String[] args args
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int under = 0;
    int top = Integer.MAX_VALUE;
    for(int i=0; i<M; i++){
      under = Math.max(sc.nextInt(),under);
      top = Math.min(sc.nextInt(),top);
    }
    int diff = top - under;
    int ans =diff + 1;
    System.out.print(((ans<0)?0:ans));
  }
}
    
