import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int cards = sc.nextInt();
    int gates = sc.nextInt();

    Integer[] start = new Integer[gates];
    Integer[] end = new Integer[gates];
    for (Integer i = 0; i < gates; i++) {
      start[i] = sc.nextInt();
      end[i] = sc.nextInt();
    }

    Arrays.sort(start, Collections.reverseOrder());
    Arrays.sort(end);

    Integer result = end[0] - start[0] + 1;

    if(result < 0) {
      result = 0;
    }

    System.out.println(result);
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int cards = sc.nextInt();
    int gates = sc.nextInt();

    Integer[] start = new Integer[gates];
    Integer[] end = new Integer[gates];
    for (Integer i = 0; i < gates; i++) {
      start[i] = sc.nextInt();
      end[i] = sc.nextInt();
    }

    Arrays.sort(start, Collections.reverseOrder());
    Arrays.sort(end);

    Integer result = end[0] - start[0] + 1;

    if(result < 0) {
      result = 0;
    }

    System.out.println(result);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int cards = sc.nextInt();
    int gates = sc.nextInt();

    Integer[] start = new Integer[gates];
    Integer[] end = new Integer[gates];
    for (Integer i = 0; i < gates; i++) {
      start[i] = sc.nextInt();
      end[i] = sc.nextInt();
    }

    Arrays.sort(start, Collections.reverseOrder());
    Arrays.sort(end);

    Integer result = end[0] - start[0] + 1;

    if(result < 0) {
      result = 0;
    }

    System.out.println(result);
  } main {
    Scanner sc = new Scanner(System.in);

    int cards = sc.nextInt();
    int gates = sc.nextInt();

    Integer[] start = new Integer[gates];
    Integer[] end = new Integer[gates];
    for (Integer i = 0; i < gates; i++) {
      start[i] = sc.nextInt();
      end[i] = sc.nextInt();
    }

    Arrays.sort(start, Collections.reverseOrder());
    Arrays.sort(end);

    Integer result = end[0] - start[0] + 1;

    if(result < 0) {
      result = 0;
    }

    System.out.println(result);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int cards = sc.nextInt(); cards sc.nextInt() sc.nextInt sc int gates = sc.nextInt(); gates sc.nextInt() sc.nextInt sc Integer[] start = new Integer[gates]; start new Integer[gates] gates Integer[] end = new Integer[gates]; end new Integer[gates] gates for (Integer i = 0; i < gates; i++) {
      start[i] = sc.nextInt();
      end[i] = sc.nextInt();
    } Integer i = 0; Integer i = 0; i 0 i < gates i gates i++ i++ i {
      start[i] = sc.nextInt();
      end[i] = sc.nextInt();
    } {
      start[i] = sc.nextInt();
      end[i] = sc.nextInt();
    } start[i] = sc.nextInt() start[i] start i sc.nextInt() sc.nextInt sc end[i] = sc.nextInt() end[i] end i sc.nextInt() sc.nextInt sc Arrays.sort(start, Collections.reverseOrder()) Arrays.sort Arrays start Collections.reverseOrder() Collections.reverseOrder Collections Arrays.sort(end) Arrays.sort Arrays end Integer result = end[0] - start[0] + 1; result end[0] - start[0] + 1 end[0] - start[0] end[0] end 0 start[0] start 0 1 if(result < 0) {
      result = 0;
    } result < 0 result 0 {
      result = 0;
    } result = 0 result 0 System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int cards = sc.nextInt();
    int gates = sc.nextInt();

    Integer[] start = new Integer[gates];
    Integer[] end = new Integer[gates];
    for (Integer i = 0; i < gates; i++) {
      start[i] = sc.nextInt();
      end[i] = sc.nextInt();
    }

    Arrays.sort(start, Collections.reverseOrder());
    Arrays.sort(end);

    Integer result = end[0] - start[0] + 1;

    if(result < 0) {
      result = 0;
    }

    System.out.println(result);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int cards = sc.nextInt();
    int gates = sc.nextInt();

    Integer[] start = new Integer[gates];
    Integer[] end = new Integer[gates];
    for (Integer i = 0; i < gates; i++) {
      start[i] = sc.nextInt();
      end[i] = sc.nextInt();
    }

    Arrays.sort(start, Collections.reverseOrder());
    Arrays.sort(end);

    Integer result = end[0] - start[0] + 1;

    if(result < 0) {
      result = 0;
    }

    System.out.println(result);
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int cards = sc.nextInt();
    int gates = sc.nextInt();

    Integer[] start = new Integer[gates];
    Integer[] end = new Integer[gates];
    for (Integer i = 0; i < gates; i++) {
      start[i] = sc.nextInt();
      end[i] = sc.nextInt();
    }

    Arrays.sort(start, Collections.reverseOrder());
    Arrays.sort(end);

    Integer result = end[0] - start[0] + 1;

    if(result < 0) {
      result = 0;
    }

    System.out.println(result);
  }
}
