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+1];
    int[] R = new int[M+1];
    for (int i = 1; i <= M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    int mostL = 1;
    int mostR = N;
    for (int i = 1; i <= M; i++) {
      if (mostL < L[i]) {
        mostL = L[i];
      }
      if (R[i] < mostR) {
        mostR = R[i];
      }
    }

    int ans = 0;
    for (int i = mostL; i <= mostR; i++) {
      ans++;
    }
        
    //System.out.println("L: " + Arrays.toString(L));
    //System.out.println("R: " + Arrays.toString(R));
    //System.out.println("cards: " + Arrays.toString(cards));
    
    System.out.println(ans);
  }
}
 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+1];
    int[] R = new int[M+1];
    for (int i = 1; i <= M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    int mostL = 1;
    int mostR = N;
    for (int i = 1; i <= M; i++) {
      if (mostL < L[i]) {
        mostL = L[i];
      }
      if (R[i] < mostR) {
        mostR = R[i];
      }
    }

    int ans = 0;
    for (int i = mostL; i <= mostR; i++) {
      ans++;
    }
        
    //System.out.println("L: " + Arrays.toString(L));
    //System.out.println("R: " + Arrays.toString(R));
    //System.out.println("cards: " + Arrays.toString(cards));
    
    System.out.println(ans);
  }
} 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+1];
    int[] R = new int[M+1];
    for (int i = 1; i <= M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    int mostL = 1;
    int mostR = N;
    for (int i = 1; i <= M; i++) {
      if (mostL < L[i]) {
        mostL = L[i];
      }
      if (R[i] < mostR) {
        mostR = R[i];
      }
    }

    int ans = 0;
    for (int i = mostL; i <= mostR; i++) {
      ans++;
    }
        
    //System.out.println("L: " + Arrays.toString(L));
    //System.out.println("R: " + Arrays.toString(R));
    //System.out.println("cards: " + Arrays.toString(cards));
    
    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] L = new int[M+1];
    int[] R = new int[M+1];
    for (int i = 1; i <= M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    int mostL = 1;
    int mostR = N;
    for (int i = 1; i <= M; i++) {
      if (mostL < L[i]) {
        mostL = L[i];
      }
      if (R[i] < mostR) {
        mostR = R[i];
      }
    }

    int ans = 0;
    for (int i = mostL; i <= mostR; i++) {
      ans++;
    }
        
    //System.out.println("L: " + Arrays.toString(L));
    //System.out.println("R: " + Arrays.toString(R));
    //System.out.println("cards: " + Arrays.toString(cards));
    
    System.out.println(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[] L = new int[M+1]; L new int[M+1] M+1 M 1 int[] R = new int[M+1]; R new int[M+1] M+1 M 1 for (int i = 1; i <= M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    } int i = 1; int i = 1; i 1 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 int mostL = 1; mostL 1 int mostR = N; mostR N for (int i = 1; i <= M; i++) {
      if (mostL < L[i]) {
        mostL = L[i];
      }
      if (R[i] < mostR) {
        mostR = R[i];
      }
    } int i = 1; int i = 1; i 1 i <= M i M i++ i++ i {
      if (mostL < L[i]) {
        mostL = L[i];
      }
      if (R[i] < mostR) {
        mostR = R[i];
      }
    } {
      if (mostL < L[i]) {
        mostL = L[i];
      }
      if (R[i] < mostR) {
        mostR = R[i];
      }
    } if (mostL < L[i]) {
        mostL = L[i];
      } mostL < L[i] mostL L[i] L i {
        mostL = L[i];
      } mostL = L[i] mostL L[i] L i if (R[i] < mostR) {
        mostR = R[i];
      } R[i] < mostR R[i] R i mostR {
        mostR = R[i];
      } mostR = R[i] mostR R[i] R i int ans = 0; ans 0 for (int i = mostL; i <= mostR; i++) {
      ans++;
    } int i = mostL; int i = mostL; i mostL i <= mostR i mostR i++ i++ i {
      ans++;
    } {
      ans++;
    } ans++ ans System.out.println(ans) System.out.println System.out System System.out ans 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+1];
    int[] R = new int[M+1];
    for (int i = 1; i <= M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    int mostL = 1;
    int mostR = N;
    for (int i = 1; i <= M; i++) {
      if (mostL < L[i]) {
        mostL = L[i];
      }
      if (R[i] < mostR) {
        mostR = R[i];
      }
    }

    int ans = 0;
    for (int i = mostL; i <= mostR; i++) {
      ans++;
    }
        
    //System.out.println("L: " + Arrays.toString(L));
    //System.out.println("R: " + Arrays.toString(R));
    //System.out.println("cards: " + Arrays.toString(cards));
    
    System.out.println(ans);
  }
} 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+1];
    int[] R = new int[M+1];
    for (int i = 1; i <= M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    int mostL = 1;
    int mostR = N;
    for (int i = 1; i <= M; i++) {
      if (mostL < L[i]) {
        mostL = L[i];
      }
      if (R[i] < mostR) {
        mostR = R[i];
      }
    }

    int ans = 0;
    for (int i = mostL; i <= mostR; i++) {
      ans++;
    }
        
    //System.out.println("L: " + Arrays.toString(L));
    //System.out.println("R: " + Arrays.toString(R));
    //System.out.println("cards: " + Arrays.toString(cards));
    
    System.out.println(ans);
  }
} 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+1];
    int[] R = new int[M+1];
    for (int i = 1; i <= M; i++) {
      L[i] = sc.nextInt();
      R[i] = sc.nextInt();
    }

    int mostL = 1;
    int mostR = N;
    for (int i = 1; i <= M; i++) {
      if (mostL < L[i]) {
        mostL = L[i];
      }
      if (R[i] < mostR) {
        mostR = R[i];
      }
    }

    int ans = 0;
    for (int i = mostL; i <= mostR; i++) {
      ans++;
    }
        
    //System.out.println("L: " + Arrays.toString(L));
    //System.out.println("R: " + Arrays.toString(R));
    //System.out.println("cards: " + Arrays.toString(cards));
    
    System.out.println(ans);
  }
}

