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