import java.util.*;
public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=0;
	     int arr[]=new int[a+2];
		 for(int i=1;i<=b;i++){
			 int m=sc.nextInt();
			 int n=sc.nextInt();
			 arr[m]=arr[m]+1;
			 arr[n+1]=arr[n+1]-1;
		 }
		 for(int i=2;i<=a+1;i++)
			 arr[i]=arr[i-1]+arr[i];
		 for(int i=1;i<=a;i++){
			  if(arr[i]>=b)
				 c++;
		 }
		 System.out.println(c);
	}
} import java.util.*; util.* java public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=0;
	     int arr[]=new int[a+2];
		 for(int i=1;i<=b;i++){
			 int m=sc.nextInt();
			 int n=sc.nextInt();
			 arr[m]=arr[m]+1;
			 arr[n+1]=arr[n+1]-1;
		 }
		 for(int i=2;i<=a+1;i++)
			 arr[i]=arr[i-1]+arr[i];
		 for(int i=1;i<=a;i++){
			  if(arr[i]>=b)
				 c++;
		 }
		 System.out.println(c);
	}
} Main public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=0;
	     int arr[]=new int[a+2];
		 for(int i=1;i<=b;i++){
			 int m=sc.nextInt();
			 int n=sc.nextInt();
			 arr[m]=arr[m]+1;
			 arr[n+1]=arr[n+1]-1;
		 }
		 for(int i=2;i<=a+1;i++)
			 arr[i]=arr[i-1]+arr[i];
		 for(int i=1;i<=a;i++){
			  if(arr[i]>=b)
				 c++;
		 }
		 System.out.println(c);
	} main {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=0;
	     int arr[]=new int[a+2];
		 for(int i=1;i<=b;i++){
			 int m=sc.nextInt();
			 int n=sc.nextInt();
			 arr[m]=arr[m]+1;
			 arr[n+1]=arr[n+1]-1;
		 }
		 for(int i=2;i<=a+1;i++)
			 arr[i]=arr[i-1]+arr[i];
		 for(int i=1;i<=a;i++){
			  if(arr[i]>=b)
				 c++;
		 }
		 System.out.println(c);
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int a=sc.nextInt(); a sc.nextInt() sc.nextInt sc int b=sc.nextInt(); b sc.nextInt() sc.nextInt sc int c=0; c 0 int arr[]=new int[a+2]; arr new int[a+2] a+2 a 2 for(int i=1;i<=b;i++){
			 int m=sc.nextInt();
			 int n=sc.nextInt();
			 arr[m]=arr[m]+1;
			 arr[n+1]=arr[n+1]-1;
		 } int i=1; int i=1; i 1 i<=b i b i++ i++ i {
			 int m=sc.nextInt();
			 int n=sc.nextInt();
			 arr[m]=arr[m]+1;
			 arr[n+1]=arr[n+1]-1;
		 } {
			 int m=sc.nextInt();
			 int n=sc.nextInt();
			 arr[m]=arr[m]+1;
			 arr[n+1]=arr[n+1]-1;
		 } int m=sc.nextInt(); m sc.nextInt() sc.nextInt sc int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc arr[m]=arr[m]+1 arr[m] arr m arr[m]+1 arr[m] arr m 1 arr[n+1]=arr[n+1]-1 arr[n+1] arr n+1 n 1 arr[n+1]-1 arr[n+1] arr n+1 n 1 1 for(int i=2;i<=a+1;i++)
			 arr[i]=arr[i-1]+arr[i]; int i=2; int i=2; i 2 i<=a+1 i a+1 a 1 i++ i++ i arr[i]=arr[i-1]+arr[i]; arr[i]=arr[i-1]+arr[i] arr[i] arr i arr[i-1]+arr[i] arr[i-1] arr i-1 i 1 arr[i] arr i for(int i=1;i<=a;i++){
			  if(arr[i]>=b)
				 c++;
		 } int i=1; int i=1; i 1 i<=a i a i++ i++ i {
			  if(arr[i]>=b)
				 c++;
		 } {
			  if(arr[i]>=b)
				 c++;
		 } if(arr[i]>=b)
				 c++; arr[i]>=b arr[i] arr i b c++ c System.out.println(c) System.out.println System.out System System.out c String arg[] arg public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=0;
	     int arr[]=new int[a+2];
		 for(int i=1;i<=b;i++){
			 int m=sc.nextInt();
			 int n=sc.nextInt();
			 arr[m]=arr[m]+1;
			 arr[n+1]=arr[n+1]-1;
		 }
		 for(int i=2;i<=a+1;i++)
			 arr[i]=arr[i-1]+arr[i];
		 for(int i=1;i<=a;i++){
			  if(arr[i]>=b)
				 c++;
		 }
		 System.out.println(c);
	}
} public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=0;
	     int arr[]=new int[a+2];
		 for(int i=1;i<=b;i++){
			 int m=sc.nextInt();
			 int n=sc.nextInt();
			 arr[m]=arr[m]+1;
			 arr[n+1]=arr[n+1]-1;
		 }
		 for(int i=2;i<=a+1;i++)
			 arr[i]=arr[i-1]+arr[i];
		 for(int i=1;i<=a;i++){
			  if(arr[i]>=b)
				 c++;
		 }
		 System.out.println(c);
	}
} Main
import java.util.*;
public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=0;
	     int arr[]=new int[a+2];
		 for(int i=1;i<=b;i++){
			 int m=sc.nextInt();
			 int n=sc.nextInt();
			 arr[m]=arr[m]+1;
			 arr[n+1]=arr[n+1]-1;
		 }
		 for(int i=2;i<=a+1;i++)
			 arr[i]=arr[i-1]+arr[i];
		 for(int i=1;i<=a;i++){
			  if(arr[i]>=b)
				 c++;
		 }
		 System.out.println(c);
	}
}