import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();

    int lo = 1, hi = n;

    for (int i = 0; i < m; ++i) {
      int l = sc.nextInt();
      int r = sc.nextInt();

      lo = (l > lo) ? l : lo;
      hi = (r < hi) ? r : hi;
    }

    System.out.println(Math.max(0, hi - lo + 1));
  }
} import java.util.Scanner; Scanner 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 lo = 1, hi = n;

    for (int i = 0; i < m; ++i) {
      int l = sc.nextInt();
      int r = sc.nextInt();

      lo = (l > lo) ? l : lo;
      hi = (r < hi) ? r : hi;
    }

    System.out.println(Math.max(0, hi - lo + 1));
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();

    int lo = 1, hi = n;

    for (int i = 0; i < m; ++i) {
      int l = sc.nextInt();
      int r = sc.nextInt();

      lo = (l > lo) ? l : lo;
      hi = (r < hi) ? r : hi;
    }

    System.out.println(Math.max(0, hi - lo + 1));
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();

    int lo = 1, hi = n;

    for (int i = 0; i < m; ++i) {
      int l = sc.nextInt();
      int r = sc.nextInt();

      lo = (l > lo) ? l : lo;
      hi = (r < hi) ? r : hi;
    }

    System.out.println(Math.max(0, hi - lo + 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 lo = 1 lo 1 hi = n; hi n for (int i = 0; i < m; ++i) {
      int l = sc.nextInt();
      int r = sc.nextInt();

      lo = (l > lo) ? l : lo;
      hi = (r < hi) ? r : hi;
    } int i = 0; int i = 0; i 0 i < m i m ++i ++i i {
      int l = sc.nextInt();
      int r = sc.nextInt();

      lo = (l > lo) ? l : lo;
      hi = (r < hi) ? r : hi;
    } {
      int l = sc.nextInt();
      int r = sc.nextInt();

      lo = (l > lo) ? l : lo;
      hi = (r < hi) ? r : hi;
    } int l = sc.nextInt(); l sc.nextInt() sc.nextInt sc int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc lo = (l > lo) ? l : lo lo (l > lo) ? l : lo (l > lo) l lo l lo hi = (r < hi) ? r : hi hi (r < hi) ? r : hi (r < hi) r hi r hi System.out.println(Math.max(0, hi - lo + 1)) System.out.println System.out System System.out Math.max(0, hi - lo + 1) Math.max Math 0 hi - lo + 1 hi - lo hi lo 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 lo = 1, hi = n;

    for (int i = 0; i < m; ++i) {
      int l = sc.nextInt();
      int r = sc.nextInt();

      lo = (l > lo) ? l : lo;
      hi = (r < hi) ? r : hi;
    }

    System.out.println(Math.max(0, hi - lo + 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 lo = 1, hi = n;

    for (int i = 0; i < m; ++i) {
      int l = sc.nextInt();
      int r = sc.nextInt();

      lo = (l > lo) ? l : lo;
      hi = (r < hi) ? r : hi;
    }

    System.out.println(Math.max(0, hi - lo + 1));
  }
} Main
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();

    int lo = 1, hi = n;

    for (int i = 0; i < m; ++i) {
      int l = sc.nextInt();
      int r = sc.nextInt();

      lo = (l > lo) ? l : lo;
      hi = (r < hi) ? r : hi;
    }

    System.out.println(Math.max(0, hi - lo + 1));
  }
}