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 nl = sc.nextInt();
    int nr = sc.nextInt();

    for (int i = 1; i < m; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      nl = Math.max(nl, l);
      nr = Math.min(nr, r);
    }

    System.out.println(Math.max((nr - nl) + 1, 0));

  }
} 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 nl = sc.nextInt();
    int nr = sc.nextInt();

    for (int i = 1; i < m; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      nl = Math.max(nl, l);
      nr = Math.min(nr, r);
    }

    System.out.println(Math.max((nr - nl) + 1, 0));

  }
} Main public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int m = sc.nextInt();
    int nl = sc.nextInt();
    int nr = sc.nextInt();

    for (int i = 1; i < m; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      nl = Math.max(nl, l);
      nr = Math.min(nr, r);
    }

    System.out.println(Math.max((nr - nl) + 1, 0));

  } main {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int m = sc.nextInt();
    int nl = sc.nextInt();
    int nr = sc.nextInt();

    for (int i = 1; i < m; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      nl = Math.max(nl, l);
      nr = Math.min(nr, r);
    }

    System.out.println(Math.max((nr - nl) + 1, 0));

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

    for (int i = 1; i < m; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      nl = Math.max(nl, l);
      nr = Math.min(nr, r);
    }

    System.out.println(Math.max((nr - nl) + 1, 0));

  }
} public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int m = sc.nextInt();
    int nl = sc.nextInt();
    int nr = sc.nextInt();

    for (int i = 1; i < m; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      nl = Math.max(nl, l);
      nr = Math.min(nr, r);
    }

    System.out.println(Math.max((nr - nl) + 1, 0));

  }
} 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 nl = sc.nextInt();
    int nr = sc.nextInt();

    for (int i = 1; i < m; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      nl = Math.max(nl, l);
      nr = Math.min(nr, r);
    }

    System.out.println(Math.max((nr - nl) + 1, 0));

  }
}