import 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 min = 0;
    int max = 100000;

    for(int i = 0;i < M;i++){
      int L = sc.nextInt();
      int R = sc.nextInt();
      
      if(min < L)min = L;
      if(max > R)max = R;
    }
    if(max - min >= 0)System.out.println(max - min+1); 
    else System.out.println("0"); 
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int min = 0;
    int max = 100000;

    for(int i = 0;i < M;i++){
      int L = sc.nextInt();
      int R = sc.nextInt();
      
      if(min < L)min = L;
      if(max > R)max = R;
    }
    if(max - min >= 0)System.out.println(max - min+1); 
    else System.out.println("0"); 
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int min = 0;
    int max = 100000;

    for(int i = 0;i < M;i++){
      int L = sc.nextInt();
      int R = sc.nextInt();
      
      if(min < L)min = L;
      if(max > R)max = R;
    }
    if(max - min >= 0)System.out.println(max - min+1); 
    else System.out.println("0"); 
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int min = 0;
    int max = 100000;

    for(int i = 0;i < M;i++){
      int L = sc.nextInt();
      int R = sc.nextInt();
      
      if(min < L)min = L;
      if(max > R)max = R;
    }
    if(max - min >= 0)System.out.println(max - min+1); 
    else System.out.println("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 min = 0; min 0 int max = 100000; max 100000 for(int i = 0;i < M;i++){
      int L = sc.nextInt();
      int R = sc.nextInt();
      
      if(min < L)min = L;
      if(max > R)max = R;
    } int i = 0; int i = 0; i 0 i < M i M i++ i++ i {
      int L = sc.nextInt();
      int R = sc.nextInt();
      
      if(min < L)min = L;
      if(max > R)max = R;
    } {
      int L = sc.nextInt();
      int R = sc.nextInt();
      
      if(min < L)min = L;
      if(max > R)max = R;
    } int L = sc.nextInt(); L sc.nextInt() sc.nextInt sc int R = sc.nextInt(); R sc.nextInt() sc.nextInt sc if(min < L)min = L; min < L min L min = L min L if(max > R)max = R; max > R max R max = R max R if(max - min >= 0)System.out.println(max - min+1); 
    else System.out.println("0"); max - min >= 0 max - min max min 0 System.out.println(max - min+1) System.out.println System.out System System.out max - min+1 max - min max min 1 System.out.println("0") System.out.println System.out System System.out "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 min = 0;
    int max = 100000;

    for(int i = 0;i < M;i++){
      int L = sc.nextInt();
      int R = sc.nextInt();
      
      if(min < L)min = L;
      if(max > R)max = R;
    }
    if(max - min >= 0)System.out.println(max - min+1); 
    else System.out.println("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 min = 0;
    int max = 100000;

    for(int i = 0;i < M;i++){
      int L = sc.nextInt();
      int R = sc.nextInt();
      
      if(min < L)min = L;
      if(max > R)max = R;
    }
    if(max - min >= 0)System.out.println(max - min+1); 
    else System.out.println("0"); 
  }
} Main
import 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 min = 0;
    int max = 100000;

    for(int i = 0;i < M;i++){
      int L = sc.nextInt();
      int R = sc.nextInt();
      
      if(min < L)min = L;
      if(max > R)max = R;
    }
    if(max - min >= 0)System.out.println(max - min+1); 
    else System.out.println("0"); 
  }
}