import java.util.*;

public class Main {
  public static void main(String[] args) {
    int number_n, number_m, i, max_left = 0, min_right = (int)Double.POSITIVE_INFINITY, answer;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    number_m = Integer.parseInt(sc.next());
    int[] card_left = new int[number_m];
    int[] card_right = new int[number_m];
    for(i = 0; i < number_m; i++) {
      card_left[i] = Integer.parseInt(sc.next());
      card_right[i] = Integer.parseInt(sc.next());
      if(card_left[i] > max_left) max_left = card_left[i];
      if(card_right[i] < min_right) min_right = card_right[i];
    }
    answer = (min_right >= max_left)? min_right - max_left + 1 : 0;
    System.out.println(answer);
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    int number_n, number_m, i, max_left = 0, min_right = (int)Double.POSITIVE_INFINITY, answer;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    number_m = Integer.parseInt(sc.next());
    int[] card_left = new int[number_m];
    int[] card_right = new int[number_m];
    for(i = 0; i < number_m; i++) {
      card_left[i] = Integer.parseInt(sc.next());
      card_right[i] = Integer.parseInt(sc.next());
      if(card_left[i] > max_left) max_left = card_left[i];
      if(card_right[i] < min_right) min_right = card_right[i];
    }
    answer = (min_right >= max_left)? min_right - max_left + 1 : 0;
    System.out.println(answer);
  }
} Main public static void main(String[] args) {
    int number_n, number_m, i, max_left = 0, min_right = (int)Double.POSITIVE_INFINITY, answer;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    number_m = Integer.parseInt(sc.next());
    int[] card_left = new int[number_m];
    int[] card_right = new int[number_m];
    for(i = 0; i < number_m; i++) {
      card_left[i] = Integer.parseInt(sc.next());
      card_right[i] = Integer.parseInt(sc.next());
      if(card_left[i] > max_left) max_left = card_left[i];
      if(card_right[i] < min_right) min_right = card_right[i];
    }
    answer = (min_right >= max_left)? min_right - max_left + 1 : 0;
    System.out.println(answer);
  } main {
    int number_n, number_m, i, max_left = 0, min_right = (int)Double.POSITIVE_INFINITY, answer;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    number_m = Integer.parseInt(sc.next());
    int[] card_left = new int[number_m];
    int[] card_right = new int[number_m];
    for(i = 0; i < number_m; i++) {
      card_left[i] = Integer.parseInt(sc.next());
      card_right[i] = Integer.parseInt(sc.next());
      if(card_left[i] > max_left) max_left = card_left[i];
      if(card_right[i] < min_right) min_right = card_right[i];
    }
    answer = (min_right >= max_left)? min_right - max_left + 1 : 0;
    System.out.println(answer);
  } int number_n number_n number_m number_m i i max_left = 0 max_left 0 min_right = (int)Double.POSITIVE_INFINITY min_right (int)Double.POSITIVE_INFINITY Double Double.POSITIVE_INFINITY answer; answer Scanner sc = new Scanner(System.in); sc new Scanner(System.in) number_n = Integer.parseInt(sc.next()) number_n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc number_m = Integer.parseInt(sc.next()) number_m Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] card_left = new int[number_m]; card_left new int[number_m] number_m int[] card_right = new int[number_m]; card_right new int[number_m] number_m for(i = 0; i < number_m; i++) {
      card_left[i] = Integer.parseInt(sc.next());
      card_right[i] = Integer.parseInt(sc.next());
      if(card_left[i] > max_left) max_left = card_left[i];
      if(card_right[i] < min_right) min_right = card_right[i];
    } i = 0; i = 0 i 0 i < number_m i number_m i++ i++ i {
      card_left[i] = Integer.parseInt(sc.next());
      card_right[i] = Integer.parseInt(sc.next());
      if(card_left[i] > max_left) max_left = card_left[i];
      if(card_right[i] < min_right) min_right = card_right[i];
    } {
      card_left[i] = Integer.parseInt(sc.next());
      card_right[i] = Integer.parseInt(sc.next());
      if(card_left[i] > max_left) max_left = card_left[i];
      if(card_right[i] < min_right) min_right = card_right[i];
    } card_left[i] = Integer.parseInt(sc.next()) card_left[i] card_left i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc card_right[i] = Integer.parseInt(sc.next()) card_right[i] card_right i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(card_left[i] > max_left) max_left = card_left[i]; card_left[i] > max_left card_left[i] card_left i max_left max_left = card_left[i] max_left card_left[i] card_left i if(card_right[i] < min_right) min_right = card_right[i]; card_right[i] < min_right card_right[i] card_right i min_right min_right = card_right[i] min_right card_right[i] card_right i answer = (min_right >= max_left)? min_right - max_left + 1 : 0 answer (min_right >= max_left)? min_right - max_left + 1 : 0 (min_right >= max_left) min_right max_left min_right - max_left + 1 min_right - max_left min_right max_left 1 0 System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {
  public static void main(String[] args) {
    int number_n, number_m, i, max_left = 0, min_right = (int)Double.POSITIVE_INFINITY, answer;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    number_m = Integer.parseInt(sc.next());
    int[] card_left = new int[number_m];
    int[] card_right = new int[number_m];
    for(i = 0; i < number_m; i++) {
      card_left[i] = Integer.parseInt(sc.next());
      card_right[i] = Integer.parseInt(sc.next());
      if(card_left[i] > max_left) max_left = card_left[i];
      if(card_right[i] < min_right) min_right = card_right[i];
    }
    answer = (min_right >= max_left)? min_right - max_left + 1 : 0;
    System.out.println(answer);
  }
} public class Main {
  public static void main(String[] args) {
    int number_n, number_m, i, max_left = 0, min_right = (int)Double.POSITIVE_INFINITY, answer;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    number_m = Integer.parseInt(sc.next());
    int[] card_left = new int[number_m];
    int[] card_right = new int[number_m];
    for(i = 0; i < number_m; i++) {
      card_left[i] = Integer.parseInt(sc.next());
      card_right[i] = Integer.parseInt(sc.next());
      if(card_left[i] > max_left) max_left = card_left[i];
      if(card_right[i] < min_right) min_right = card_right[i];
    }
    answer = (min_right >= max_left)? min_right - max_left + 1 : 0;
    System.out.println(answer);
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    int number_n, number_m, i, max_left = 0, min_right = (int)Double.POSITIVE_INFINITY, answer;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    number_m = Integer.parseInt(sc.next());
    int[] card_left = new int[number_m];
    int[] card_right = new int[number_m];
    for(i = 0; i < number_m; i++) {
      card_left[i] = Integer.parseInt(sc.next());
      card_right[i] = Integer.parseInt(sc.next());
      if(card_left[i] > max_left) max_left = card_left[i];
      if(card_right[i] < min_right) min_right = card_right[i];
    }
    answer = (min_right >= max_left)? min_right - max_left + 1 : 0;
    System.out.println(answer);
  }
}
