import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();

    int left = 0;
    int right = N;
    for (int i = 0; i < M; i++) {
      left = Math.max(left, scanner.nextInt());
      right = Math.min(right, scanner.nextInt());
    }
    System.out.println(Math.max(right - left + 1, 0));
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();

    int left = 0;
    int right = N;
    for (int i = 0; i < M; i++) {
      left = Math.max(left, scanner.nextInt());
      right = Math.min(right, scanner.nextInt());
    }
    System.out.println(Math.max(right - left + 1, 0));
  }
} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();

    int left = 0;
    int right = N;
    for (int i = 0; i < M; i++) {
      left = Math.max(left, scanner.nextInt());
      right = Math.min(right, scanner.nextInt());
    }
    System.out.println(Math.max(right - left + 1, 0));
  } main {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();

    int left = 0;
    int right = N;
    for (int i = 0; i < M; i++) {
      left = Math.max(left, scanner.nextInt());
      right = Math.min(right, scanner.nextInt());
    }
    System.out.println(Math.max(right - left + 1, 0));
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int M = scanner.nextInt(); M scanner.nextInt() scanner.nextInt scanner int left = 0; left 0 int right = N; right N for (int i = 0; i < M; i++) {
      left = Math.max(left, scanner.nextInt());
      right = Math.min(right, scanner.nextInt());
    } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
      left = Math.max(left, scanner.nextInt());
      right = Math.min(right, scanner.nextInt());
    } {
      left = Math.max(left, scanner.nextInt());
      right = Math.min(right, scanner.nextInt());
    } left = Math.max(left, scanner.nextInt()) left Math.max(left, scanner.nextInt()) Math.max Math left scanner.nextInt() scanner.nextInt scanner right = Math.min(right, scanner.nextInt()) right Math.min(right, scanner.nextInt()) Math.min Math right scanner.nextInt() scanner.nextInt scanner System.out.println(Math.max(right - left + 1, 0)) System.out.println System.out System System.out Math.max(right - left + 1, 0) Math.max Math right - left + 1 right - left right left 1 0 String[] args args public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();

    int left = 0;
    int right = N;
    for (int i = 0; i < M; i++) {
      left = Math.max(left, scanner.nextInt());
      right = Math.min(right, scanner.nextInt());
    }
    System.out.println(Math.max(right - left + 1, 0));
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();

    int left = 0;
    int right = N;
    for (int i = 0; i < M; i++) {
      left = Math.max(left, scanner.nextInt());
      right = Math.min(right, scanner.nextInt());
    }
    System.out.println(Math.max(right - left + 1, 0));
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int M = scanner.nextInt();

    int left = 0;
    int right = N;
    for (int i = 0; i < M; i++) {
      left = Math.max(left, scanner.nextInt());
      right = Math.min(right, scanner.nextInt());
    }
    System.out.println(Math.max(right - left + 1, 0));
  }
}
