import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int max = 0, min = 100000;
    for(int i = 0; i < m; i++){
      max = Math.max(max , sc.nextInt());
      min = Math.min(min , sc.nextInt());
    }
    if(min < max) System.out.println(0);
    else System.out.println(min - max + 1);
  } 
} import java.util.*; util.* java class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int max = 0, min = 100000;
    for(int i = 0; i < m; i++){
      max = Math.max(max , sc.nextInt());
      min = Math.min(min , sc.nextInt());
    }
    if(min < max) System.out.println(0);
    else System.out.println(min - max + 1);
  } 
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int max = 0, min = 100000;
    for(int i = 0; i < m; i++){
      max = Math.max(max , sc.nextInt());
      min = Math.min(min , sc.nextInt());
    }
    if(min < max) System.out.println(0);
    else System.out.println(min - max + 1);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int max = 0, min = 100000;
    for(int i = 0; i < m; i++){
      max = Math.max(max , sc.nextInt());
      min = Math.min(min , sc.nextInt());
    }
    if(min < max) System.out.println(0);
    else System.out.println(min - max + 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 max = 0 max 0 min = 100000; min 100000 for(int i = 0; i < m; i++){
      max = Math.max(max , sc.nextInt());
      min = Math.min(min , sc.nextInt());
    } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
      max = Math.max(max , sc.nextInt());
      min = Math.min(min , sc.nextInt());
    } {
      max = Math.max(max , sc.nextInt());
      min = Math.min(min , sc.nextInt());
    } max = Math.max(max , sc.nextInt()) max Math.max(max , sc.nextInt()) Math.max Math max sc.nextInt() sc.nextInt sc min = Math.min(min , sc.nextInt()) min Math.min(min , sc.nextInt()) Math.min Math min sc.nextInt() sc.nextInt sc if(min < max) System.out.println(0);
    else System.out.println(min - max + 1); min < max min max System.out.println(0) System.out.println System.out System System.out 0 System.out.println(min - max + 1) System.out.println System.out System System.out min - max + 1 min - max min max 1 String[] args args
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int max = 0, min = 100000;
    for(int i = 0; i < m; i++){
      max = Math.max(max , sc.nextInt());
      min = Math.min(min , sc.nextInt());
    }
    if(min < max) System.out.println(0);
    else System.out.println(min - max + 1);
  } 
}
