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 G[] = new int[N+2];
    for (int i = 0; i < M; i++) {
      G[sc.nextInt()]++;
      G[sc.nextInt()+1]--;
    }
    int count = 0;
    for (int i = 1; i < N+2; i++) {
      if (i > 0) {
        G[i] += G[i - 1];
      }
      if (G[i] == M) count++;
    }
    System.out.println(count);
  }
} 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 G[] = new int[N+2];
    for (int i = 0; i < M; i++) {
      G[sc.nextInt()]++;
      G[sc.nextInt()+1]--;
    }
    int count = 0;
    for (int i = 1; i < N+2; i++) {
      if (i > 0) {
        G[i] += G[i - 1];
      }
      if (G[i] == M) count++;
    }
    System.out.println(count);
  }
} Main public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int M = sc.nextInt();
    int G[] = new int[N+2];
    for (int i = 0; i < M; i++) {
      G[sc.nextInt()]++;
      G[sc.nextInt()+1]--;
    }
    int count = 0;
    for (int i = 1; i < N+2; i++) {
      if (i > 0) {
        G[i] += G[i - 1];
      }
      if (G[i] == M) count++;
    }
    System.out.println(count);
  } main {
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int M = sc.nextInt();
    int G[] = new int[N+2];
    for (int i = 0; i < M; i++) {
      G[sc.nextInt()]++;
      G[sc.nextInt()+1]--;
    }
    int count = 0;
    for (int i = 1; i < N+2; i++) {
      if (i > 0) {
        G[i] += G[i - 1];
      }
      if (G[i] == M) count++;
    }
    System.out.println(count);
  } 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 G[] = new int[N+2]; G new int[N+2] N+2 N 2 for (int i = 0; i < M; i++) {
      G[sc.nextInt()]++;
      G[sc.nextInt()+1]--;
    } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
      G[sc.nextInt()]++;
      G[sc.nextInt()+1]--;
    } {
      G[sc.nextInt()]++;
      G[sc.nextInt()+1]--;
    } G[sc.nextInt()]++ G[sc.nextInt()] G sc.nextInt() sc.nextInt sc G[sc.nextInt()+1]-- G[sc.nextInt()+1] G sc.nextInt()+1 sc.nextInt() sc.nextInt sc 1 int count = 0; count 0 for (int i = 1; i < N+2; i++) {
      if (i > 0) {
        G[i] += G[i - 1];
      }
      if (G[i] == M) count++;
    } int i = 1; int i = 1; i 1 i < N+2 i N+2 N 2 i++ i++ i {
      if (i > 0) {
        G[i] += G[i - 1];
      }
      if (G[i] == M) count++;
    } {
      if (i > 0) {
        G[i] += G[i - 1];
      }
      if (G[i] == M) count++;
    } if (i > 0) {
        G[i] += G[i - 1];
      } i > 0 i 0 {
        G[i] += G[i - 1];
      } G[i] += G[i - 1] G[i] G i G[i - 1] G i - 1 i 1 if (G[i] == M) count++; G[i] == M G[i] G i M count++ count System.out.println(count) System.out.println System.out System System.out count 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 G[] = new int[N+2];
    for (int i = 0; i < M; i++) {
      G[sc.nextInt()]++;
      G[sc.nextInt()+1]--;
    }
    int count = 0;
    for (int i = 1; i < N+2; i++) {
      if (i > 0) {
        G[i] += G[i - 1];
      }
      if (G[i] == M) count++;
    }
    System.out.println(count);
  }
}
