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[] l=new int[m];
  		int[] r=new int[m];
		for(int c=0;c<m;c++){
    		l[c]=sc.nextInt();
          	r[c]=sc.nextInt();
    	}
  		int max=r[0];
  		int min=l[0];
    for(int a=0;a<m-1;a++){
 	if(max<l[a+1]){
      		max=-1; 
      		min=0;
    		break;
    	}else if(r[a+1]<min){
      		max=-1;
      		min=0;
     		break;
   	 }
      max=Math.min(r[a+1],max);
      min=Math.max(l[a+1],min);
    }

    	System.out.println(max-min+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[] l=new int[m];
  		int[] r=new int[m];
		for(int c=0;c<m;c++){
    		l[c]=sc.nextInt();
          	r[c]=sc.nextInt();
    	}
  		int max=r[0];
  		int min=l[0];
    for(int a=0;a<m-1;a++){
 	if(max<l[a+1]){
      		max=-1; 
      		min=0;
    		break;
    	}else if(r[a+1]<min){
      		max=-1;
      		min=0;
     		break;
   	 }
      max=Math.min(r[a+1],max);
      min=Math.max(l[a+1],min);
    }

    	System.out.println(max-min+1);
    }
} Main public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
		
		int[] l=new int[m];
  		int[] r=new int[m];
		for(int c=0;c<m;c++){
    		l[c]=sc.nextInt();
          	r[c]=sc.nextInt();
    	}
  		int max=r[0];
  		int min=l[0];
    for(int a=0;a<m-1;a++){
 	if(max<l[a+1]){
      		max=-1; 
      		min=0;
    		break;
    	}else if(r[a+1]<min){
      		max=-1;
      		min=0;
     		break;
   	 }
      max=Math.min(r[a+1],max);
      min=Math.max(l[a+1],min);
    }

    	System.out.println(max-min+1);
    } main {
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
		
		int[] l=new int[m];
  		int[] r=new int[m];
		for(int c=0;c<m;c++){
    		l[c]=sc.nextInt();
          	r[c]=sc.nextInt();
    	}
  		int max=r[0];
  		int min=l[0];
    for(int a=0;a<m-1;a++){
 	if(max<l[a+1]){
      		max=-1; 
      		min=0;
    		break;
    	}else if(r[a+1]<min){
      		max=-1;
      		min=0;
     		break;
   	 }
      max=Math.min(r[a+1],max);
      min=Math.max(l[a+1],min);
    }

    	System.out.println(max-min+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[] l=new int[m]; l new int[m] m int[] r=new int[m]; r new int[m] m for(int c=0;c<m;c++){
    		l[c]=sc.nextInt();
          	r[c]=sc.nextInt();
    	} int c=0; int c=0; c 0 c<m c m c++ c++ c {
    		l[c]=sc.nextInt();
          	r[c]=sc.nextInt();
    	} {
    		l[c]=sc.nextInt();
          	r[c]=sc.nextInt();
    	} l[c]=sc.nextInt() l[c] l c sc.nextInt() sc.nextInt sc r[c]=sc.nextInt() r[c] r c sc.nextInt() sc.nextInt sc int max=r[0]; max r[0] r 0 int min=l[0]; min l[0] l 0 for(int a=0;a<m-1;a++){
 	if(max<l[a+1]){
      		max=-1; 
      		min=0;
    		break;
    	}else if(r[a+1]<min){
      		max=-1;
      		min=0;
     		break;
   	 }
      max=Math.min(r[a+1],max);
      min=Math.max(l[a+1],min);
    } int a=0; int a=0; a 0 a<m-1 a m-1 m 1 a++ a++ a {
 	if(max<l[a+1]){
      		max=-1; 
      		min=0;
    		break;
    	}else if(r[a+1]<min){
      		max=-1;
      		min=0;
     		break;
   	 }
      max=Math.min(r[a+1],max);
      min=Math.max(l[a+1],min);
    } {
 	if(max<l[a+1]){
      		max=-1; 
      		min=0;
    		break;
    	}else if(r[a+1]<min){
      		max=-1;
      		min=0;
     		break;
   	 }
      max=Math.min(r[a+1],max);
      min=Math.max(l[a+1],min);
    } if(max<l[a+1]){
      		max=-1; 
      		min=0;
    		break;
    	}else if(r[a+1]<min){
      		max=-1;
      		min=0;
     		break;
   	 } max<l[a+1] max l[a+1] l a+1 a 1 {
      		max=-1; 
      		min=0;
    		break;
    	} max=-1 max -1 1 min=0 min 0 break; if(r[a+1]<min){
      		max=-1;
      		min=0;
     		break;
   	 } r[a+1]<min r[a+1] r a+1 a 1 min {
      		max=-1;
      		min=0;
     		break;
   	 } max=-1 max -1 1 min=0 min 0 break; max=Math.min(r[a+1],max) max Math.min(r[a+1],max) Math.min Math r[a+1] r a+1 a 1 max min=Math.max(l[a+1],min) min Math.max(l[a+1],min) Math.max Math l[a+1] l a+1 a 1 min System.out.println(max-min+1) System.out.println System.out System System.out max-min+1 max-min max min 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[] l=new int[m];
  		int[] r=new int[m];
		for(int c=0;c<m;c++){
    		l[c]=sc.nextInt();
          	r[c]=sc.nextInt();
    	}
  		int max=r[0];
  		int min=l[0];
    for(int a=0;a<m-1;a++){
 	if(max<l[a+1]){
      		max=-1; 
      		min=0;
    		break;
    	}else if(r[a+1]<min){
      		max=-1;
      		min=0;
     		break;
   	 }
      max=Math.min(r[a+1],max);
      min=Math.max(l[a+1],min);
    }

    	System.out.println(max-min+1);
    }
}
