import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int left = 0;
    int right = n+1;
    int tmpLeft , tmpRight;
    for(int i=0;i<m;i++){
      
      tmpLeft = Integer.parseInt(sc.next());
      tmpRight = Integer.parseInt(sc.next());
      if(tmpLeft>left)left = tmpLeft;
      if(tmpRight<right)right = tmpRight;
    }
    if(right>=left){
      System.out.print(right-left+1);
    }else{
      System.out.print(0);
    }
   
    System.out.flush();
    
  }
} import java.util.Scanner; Scanner java.util class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int left = 0;
    int right = n+1;
    int tmpLeft , tmpRight;
    for(int i=0;i<m;i++){
      
      tmpLeft = Integer.parseInt(sc.next());
      tmpRight = Integer.parseInt(sc.next());
      if(tmpLeft>left)left = tmpLeft;
      if(tmpRight<right)right = tmpRight;
    }
    if(right>=left){
      System.out.print(right-left+1);
    }else{
      System.out.print(0);
    }
   
    System.out.flush();
    
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int left = 0;
    int right = n+1;
    int tmpLeft , tmpRight;
    for(int i=0;i<m;i++){
      
      tmpLeft = Integer.parseInt(sc.next());
      tmpRight = Integer.parseInt(sc.next());
      if(tmpLeft>left)left = tmpLeft;
      if(tmpRight<right)right = tmpRight;
    }
    if(right>=left){
      System.out.print(right-left+1);
    }else{
      System.out.print(0);
    }
   
    System.out.flush();
    
  } main {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int left = 0;
    int right = n+1;
    int tmpLeft , tmpRight;
    for(int i=0;i<m;i++){
      
      tmpLeft = Integer.parseInt(sc.next());
      tmpRight = Integer.parseInt(sc.next());
      if(tmpLeft>left)left = tmpLeft;
      if(tmpRight<right)right = tmpRight;
    }
    if(right>=left){
      System.out.print(right-left+1);
    }else{
      System.out.print(0);
    }
   
    System.out.flush();
    
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int m = Integer.parseInt(sc.next()); m Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int left = 0; left 0 int right = n+1; right n+1 n 1 int tmpLeft tmpLeft tmpRight; tmpRight for(int i=0;i<m;i++){
      
      tmpLeft = Integer.parseInt(sc.next());
      tmpRight = Integer.parseInt(sc.next());
      if(tmpLeft>left)left = tmpLeft;
      if(tmpRight<right)right = tmpRight;
    } int i=0; int i=0; i 0 i<m i m i++ i++ i {
      
      tmpLeft = Integer.parseInt(sc.next());
      tmpRight = Integer.parseInt(sc.next());
      if(tmpLeft>left)left = tmpLeft;
      if(tmpRight<right)right = tmpRight;
    } {
      
      tmpLeft = Integer.parseInt(sc.next());
      tmpRight = Integer.parseInt(sc.next());
      if(tmpLeft>left)left = tmpLeft;
      if(tmpRight<right)right = tmpRight;
    } tmpLeft = Integer.parseInt(sc.next()) tmpLeft Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc tmpRight = Integer.parseInt(sc.next()) tmpRight Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(tmpLeft>left)left = tmpLeft; tmpLeft>left tmpLeft left left = tmpLeft left tmpLeft if(tmpRight<right)right = tmpRight; tmpRight<right tmpRight right right = tmpRight right tmpRight if(right>=left){
      System.out.print(right-left+1);
    }else{
      System.out.print(0);
    } right>=left right left {
      System.out.print(right-left+1);
    } System.out.print(right-left+1) System.out.print System.out System System.out right-left+1 right-left right left 1 {
      System.out.print(0);
    } System.out.print(0) System.out.print System.out System System.out 0 System.out.flush() System.out.flush System.out System System.out String[] args args
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int m = Integer.parseInt(sc.next());
    int left = 0;
    int right = n+1;
    int tmpLeft , tmpRight;
    for(int i=0;i<m;i++){
      
      tmpLeft = Integer.parseInt(sc.next());
      tmpRight = Integer.parseInt(sc.next());
      if(tmpLeft>left)left = tmpLeft;
      if(tmpRight<right)right = tmpRight;
    }
    if(right>=left){
      System.out.print(right-left+1);
    }else{
      System.out.print(0);
    }
   
    System.out.flush();
    
  }
}