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];

    for (int i = 0; i < M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    sc.close();

    int min = 0;
    int max = N;

    for (int i = 0; i < M; i++) {
      min = Math.max(L[i], min);
      max = Math.min(R[i], max);
    }

    if (max < min){
      System.out.println(0);
    } else {
      System.out.println(max - min + 1);
    }
 
  }

} 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];

    for (int i = 0; i < M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    sc.close();

    int min = 0;
    int max = N;

    for (int i = 0; i < M; i++) {
      min = Math.max(L[i], min);
      max = Math.min(R[i], max);
    }

    if (max < min){
      System.out.println(0);
    } else {
      System.out.println(max - min + 1);
    }
 
  }

} 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];

    for (int i = 0; i < M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    sc.close();

    int min = 0;
    int max = N;

    for (int i = 0; i < M; i++) {
      min = Math.max(L[i], min);
      max = Math.min(R[i], max);
    }

    if (max < min){
      System.out.println(0);
    } else {
      System.out.println(max - min + 1);
    }
 
  } 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];

    for (int i = 0; i < M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    sc.close();

    int min = 0;
    int max = N;

    for (int i = 0; i < M; i++) {
      min = Math.max(L[i], min);
      max = Math.min(R[i], max);
    }

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

    for (int i = 0; i < M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    sc.close();

    int min = 0;
    int max = N;

    for (int i = 0; i < M; i++) {
      min = Math.max(L[i], min);
      max = Math.min(R[i], max);
    }

    if (max < min){
      System.out.println(0);
    } else {
      System.out.println(max - min + 1);
    }
 
  }

} 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];

    for (int i = 0; i < M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    sc.close();

    int min = 0;
    int max = N;

    for (int i = 0; i < M; i++) {
      min = Math.max(L[i], min);
      max = Math.min(R[i], max);
    }

    if (max < min){
      System.out.println(0);
    } else {
      System.out.println(max - min + 1);
    }
 
  }

} 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];

    for (int i = 0; i < M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    sc.close();

    int min = 0;
    int max = N;

    for (int i = 0; i < M; i++) {
      min = Math.max(L[i], min);
      max = Math.min(R[i], max);
    }

    if (max < min){
      System.out.println(0);
    } else {
      System.out.println(max - min + 1);
    }
 
  }

}